Esempio n. 1
0
 public static void SaveAOI(List <Model.AOI> aois, string fileName)
 {
     try
     {
         StringBuilder sb  = new StringBuilder();
         int           con = 0;
         //var idsList = Getids(fileName);
         foreach (var a in aois)
         {
             try
             {
                 //if (idsList.Contains([email protected])) continue;
                 if (a.data.spec == null || a.data.spec.mining_shape == null || a.data.spec.mining_shape.shape == null)
                 {
                     continue;
                 }
                 string wgs_loaction = "";
                 string cen          = a.data.spec.mining_shape.center;
                 if (cen != "" && cen.Contains(","))
                 {
                     //火星坐标转为WGS84坐标
                     LngLatPoint wgs = new Transform().GCJ2WGS(double.Parse(cen.Split(',')[1]), double.Parse(cen.Split(',')[0]));
                     wgs_loaction = wgs.Lng + "," + wgs.Lat;
                 }
                 string s = string.Empty;
                 s += [email protected] + " ";
                 s += a.data.spec.mining_shape.area + " ";
                 s += wgs_loaction + " ";
                 s += [email protected] + " " + [email protected]_name + " " + [email protected] + " ";
                 s += AppConst.GetWGSPointStr(a.data.spec.mining_shape.shape) + "\r\n";
                 sb.Append(s);
                 con += 1;
             }
             catch (Exception ex)
             {
                 new Log().PageLog.Error(string.Format("保存AOI数据:{0}", ex));
             }
         }
         Console.WriteLine(string.Format("下载{0}条数据", con));
         FileStream fs = File.OpenWrite(fileName);
         fs.Position = fs.Length;
         byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());
         fs.Write(bytes, 0, bytes.Length);
         fs.Dispose();
         fs.Close();
     }
     catch (Exception ex)
     {
         new Log().PageLog.Error(string.Format("保存AOI数据:{0}", ex));
     }
 }
Esempio n. 2
0
        //[STAThread]
        static void Main(string[] args)
        {
            //启动时加载日志
            string logpath = AppDomain.CurrentDomain.BaseDirectory + "log4net.xml";

            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(logpath));
            string resultPath = AppDomain.CurrentDomain.BaseDirectory + "\\Result\\";
            //获取配置文件
            List <Citys>  citys = AppConst.GetConfigCitys();
            List <Scenes> scens = AppConst.GetConfigScenes();

            if (AppConst.IsDownPOI == "是")
            {
                ThreadPool.SetMaxThreads(10, 10);
                ThreadPool.SetMinThreads(5, 10);
                List <WaitHandle> waitHandles = new List <WaitHandle>();
                Console.WriteLine("开始下载POI数据.....");
                foreach (Scenes scene in scens)
                {
                    foreach (Citys city in citys)
                    {
                        try
                        {
                            // 场景大类/场景中类/场景小类/省份/地市-区县-.txt
                            string subPath  = string.Format("{0}/{1}/{2}/{3}/{4}/", scene.l_class, scene.m_class, scene.s_class, city.Province, city.CityName);
                            string fileName = resultPath + subPath + city.Country + ".txt";
                            //先判断文件是否存在 存在的话 即定位改地市已经下载
                            if (File.Exists(fileName))
                            {
                                //File.Delete(fileName);
                                continue;
                            }
                            //创建目录
                            if (!Directory.Exists(resultPath + subPath))
                            {
                                Directory.CreateDirectory(resultPath + subPath);
                            }
                            //创建文件
                            File.Create(fileName).Dispose();

                            //下载POI数据
                            Console.WriteLine("- - - - - - - - - - - - - - - - - - - - - - ");
                            Console.WriteLine(string.Format("请求{0}-{1}-{2}-{3}-{4}-{5}-POI数据", scene.l_class, scene.m_class, scene.s_class, city.Province, city.CityName, city.Country));

                            if (waitHandles.Count > 40)
                            {
                                WaitHandle.WaitAll(waitHandles.ToArray());
                                waitHandles = new List <WaitHandle>();
                            }
                            AutoResetEvent wh    = new AutoResetEvent(false);
                            ThreadPameM    pameM = new ThreadPameM()
                            {
                                FilePath = fileName, Wait = wh, city = city, scene = scene
                            };
                            ThreadPool.QueueUserWorkItem(new WaitCallback(POIA.DownPoiData), pameM);
                            waitHandles.Add(wh);
                        }
                        catch (Exception ex)
                        {
                            new Log().PageLog.Error(ex);
                        }
                    }
                }
                if (waitHandles.Count != 0)
                {
                    WaitHandle.WaitAll(waitHandles.ToArray());
                }
                waitHandles = new List <WaitHandle>();
            }
            if (AppConst.IsDownAOI == "是")
            {
                ThreadPool.SetMaxThreads(AppConst.AoiThreadTimes, AppConst.AoiThreadTimes);
                ThreadPool.SetMinThreads(AppConst.AoiThreadTimes, AppConst.AoiThreadTimes);
                List <WaitHandle> waitHandles = new List <WaitHandle>();
                Console.WriteLine("开始下载AOI数据.....");
                for (int i = 0; i < AppConst.DownAOITimes; i++)
                {
                    foreach (Scenes scene in scens)
                    {
                        foreach (Citys city in citys)
                        {
                            try
                            {
                                // 场景大类/场景中类/场景小类/省份/地市-区县-.txt
                                string subPath  = string.Format("{0}\\{1}\\{2}\\{3}\\{4}\\", scene.l_class, scene.m_class, scene.s_class, city.Province, city.CityName);
                                string fileName = resultPath + subPath + city.Country + "-AOI.txt";
                                //下载AOI数据
                                Console.WriteLine("- - - - - - - - - - - - - - - - - - - - - -");
                                Console.WriteLine(string.Format("请求{0}-{1}-{2}-{3}-{4}-{5}-AOI数据", scene.l_class, scene.m_class, scene.s_class, city.Province, city.CityName, city.Country));
                                if (waitHandles.Count > 40)
                                {
                                    WaitHandle.WaitAll(waitHandles.ToArray());
                                    waitHandles = new List <WaitHandle>();
                                }
                                AutoResetEvent wh    = new AutoResetEvent(false);
                                ThreadPameM    pameM = new ThreadPameM()
                                {
                                    FilePath = fileName, Wait = wh, OverTimes = i + 1
                                };
                                ThreadPool.QueueUserWorkItem(new WaitCallback(AOIAction.GetAOI), pameM);
                                waitHandles.Add(wh);
                            }
                            catch (Exception ex)
                            {
                                new Log().PageLog.Error(ex);
                            }
                        }
                    }
                }
                if (waitHandles.Count != 0)
                {
                    WaitHandle.WaitAll(waitHandles.ToArray());
                }
                waitHandles = new List <WaitHandle>();
                for (int i = 0; i < AppConst.CalDownAOITimes; i++)
                {
                    foreach (Scenes scene in scens)
                    {
                        foreach (Citys city in citys)
                        {
                            try
                            {
                                // 场景大类/场景中类/场景小类/省份/地市-区县-.txt
                                string subPath  = string.Format("{0}\\{1}\\{2}\\{3}\\{4}\\", scene.l_class, scene.m_class, scene.s_class, city.Province, city.CityName);
                                string fileName = resultPath + subPath + city.Country + "-AOI.txt";
                                //下载AOI数据
                                Console.WriteLine("- - - - - - - - - - - - - - - - - - - - - -");
                                Console.WriteLine(string.Format("请求{0}-{1}-{2}-{3}-{4}-{5}-AOI数据", scene.l_class, scene.m_class, scene.s_class, city.Province, city.CityName, city.Country));
                                if (waitHandles.Count > 40)
                                {
                                    WaitHandle.WaitAll(waitHandles.ToArray());
                                    waitHandles = new List <WaitHandle>();
                                }
                                AutoResetEvent wh    = new AutoResetEvent(false);
                                ThreadPameM    pameM = new ThreadPameM()
                                {
                                    FilePath = fileName, Wait = wh
                                };
                                ThreadPool.QueueUserWorkItem(new WaitCallback(AOIAction.GetAOIDtl), pameM);
                                waitHandles.Add(wh);
                            }
                            catch (Exception ex)
                            {
                                new Log().PageLog.Error(ex);
                            }
                        }
                    }
                }
                if (waitHandles.Count != 0)
                {
                    WaitHandle.WaitAll(waitHandles.ToArray());
                }
                int allCount = 0;
                foreach (Scenes scene in scens)
                {
                    foreach (Citys city in citys)
                    {
                        try
                        {
                            // 场景大类/场景中类/场景小类/省份/地市-区县-.txt
                            string subPath  = string.Format("{0}\\{1}\\{2}\\{3}\\{4}\\", scene.l_class, scene.m_class, scene.s_class, city.Province, city.CityName);
                            string fileName = resultPath + subPath + city.Country + "-AOI.txt";
                            //下载AOI数据
                            Console.WriteLine("- - - - - - - - - - - - - - - - - - - - - -");
                            Console.WriteLine(string.Format("请求{0}-{1}-{2}-{3}-{4}-{5}-AOI数据", scene.l_class, scene.m_class, scene.s_class, city.Province, city.CityName, city.Country));
                            allCount += AOIAction.TongJiAOIDtl(fileName);
                        }
                        catch (Exception ex)
                        {
                            new Log().PageLog.Error(ex);
                        }
                    }
                }
                Console.WriteLine($"本次共找到AOI数据{allCount}条");
                Console.ReadKey();
            }
        }