Beispiel #1
0
        public static String[] GetWayIdsInBound(Aram.OSMParser.Bounds bound)
        {
            NpgsqlConnection con = new NpgsqlConnection(conPostGreGIS);

            con.Open();
            NpgsqlCommand com = new NpgsqlCommand("", con);

            com.CommandText = "select wayId from WayNodeInfoAram_cachedFromView " //"select wayId from viewWayNodeInfoAram "
                                                                                  // + String.Format("where wayid in (select way_id from networkways) and Latitude between {0} and {1} and Longitude between {2} and {3} ",
                              + String.Format("where Latitude between {0} and {1} and Longitude between {2} and {3} ",
                                              (int)(bound.minlat * scale), (int)(bound.maxlat * scale), (int)(bound.minlon * scale), (int)(bound.maxlon * scale))
                              + "group by wayId";
            com.CommandText = com.CommandText.Replace(",", ".");
            NpgsqlDataReader reader = com.ExecuteReader();
            List <String>    temp   = new List <string>();

            while (reader.Read())
            {
                temp.Add(reader[0].ToString());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            con.Close();
            return(temp.ToArray());
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Stopwatch watch       = new Stopwatch();
            Stopwatch recordmeter = new Stopwatch();

            Aram.OSMParser.Bounds b = new Aram.OSMParser.Bounds();
            b.minlat = 59.32973;
            b.maxlat = 59.34481;
            b.minlon = 18.07556;
            b.maxlon = 18.1062;

            if (args.Length == 1)
            {
                conPostGreGIS = conPostGreGIS.Replace("127.0.0.1", args[0]);
            }

            if (args.Length == 5)
            {
                conPostGreGIS = conPostGreGIS.Replace("127.0.0.1", args[0]);
                b.minlat      = double.Parse(args[1]);
                b.maxlat      = double.Parse(args[2]);
                b.minlon      = double.Parse(args[3]);
                b.maxlon      = double.Parse(args[4]);
            }

            Console.WriteLine("Preprocessing...");
            ClearWayExtData();
            PerformPreprocessingForWay_ext();
            Console.WriteLine("Preprocessing is finished.");
            //conn.Open();

            var ids     = GetWayIdsInBound(b);         //GetWayIdsInStockholm();
            int idcount = 0;


            int    progress        = 1;
            object lockTransaction = new object();
            object lockCounter     = new object();

            watch.Start();
            Parallel.ForEach <String>(ids, (id) =>
            {
                //lock (lockTransaction)
                //{
                //		Console.Clear();
                //		Console.WriteLine(
                //				"Generating segments for " + id + "\n" + progress + "/" + ids.Length + "\t" + (100 * progress / (float)ids.Length).ToString("0.00") + "%");
                //}
                NpgsqlConnection conn = new NpgsqlConnection(conPostGreGIS);
                conn.Open();
                NpgsqlTransaction trans = conn.BeginTransaction();
                Interlocked.Increment(ref progress);
                //progress++;
                if (IsHighway(id, conn))
                {
                    var nodes    = GetWay(conn, id);
                    var lastnode = 0;
                    var oneway   = IsOneWay(conn, id);
                    for (int i = 1; i < nodes.Count; i++)                     // we skip the first nodes in the way.
                    {
                        if (CheckConnectivity(conn, nodes[i][0]))             // if it is connected, start a way
                        {
                            int newseqforward = 0;
                            int newseqreverse = 0;
                            if (oneway == 1 || oneway == 0)
                            {
                                int localcount;
                                lock (lockCounter)
                                {
                                    localcount = idcount;
                                    idcount++;
                                }
                                for (int j = lastnode; j <= i; j++)
                                {
                                    InsertNew_Way_ext(conn, localcount, nodes[j][0], newseqforward, id, lastnode, i);
                                    newseqforward++;
                                }
                            }

                            if (oneway == -1 || oneway == 0)
                            {
                                int localcount;
                                lock (lockCounter)
                                {
                                    localcount = idcount;
                                    idcount++;
                                }
                                for (int j = i; j >= lastnode; j--)
                                {
                                    InsertNew_Way_ext(conn, localcount, nodes[j][0], newseqreverse, id, i, lastnode);
                                    newseqreverse++;
                                }
                            }
                            lastnode = i;
                        }
                    }
                }
                else
                {
                    // just copy to destination
                    var nodes = GetWay(conn, id);
                    int localcount;
                    lock (lockCounter)
                    {
                        localcount = idcount;
                        idcount++;
                    }
                    for (int i = 0; i < nodes.Count; i++)                     // we skip the first nodes in the way.
                    {
                        InsertNew_Way_ext(conn, localcount, nodes[i][0], i, id, 0, nodes.Count - 1);
                    }
                }
                trans.Commit();
                conn.Close();
            });
            Console.WriteLine("Postprocessing...");
            PerformPostprocessingForWay_ext();
            Console.WriteLine("Postprocessing is finished.");
            watch.Stop();
            Console.WriteLine(
                String.Format(
                    "Segment generation was completed in {0} hrs and {1} mins and {2} seconds", watch.Elapsed.Hours, watch.Elapsed.Minutes, watch.Elapsed.Seconds));
            Console.ReadKey();
        }