码迷,mamicode.com
首页 > 数据库 > 详细

PGIS下载离线地图 SQLite+WPF

时间:2015-12-22 10:26:18      阅读:931      评论:0      收藏:0      [点我收藏+]

标签:

项目是超高分辨率屏幕墙,实时在线加载PGIS地图速度会比较慢,造成屏幕大量留白。于是使用地图缓存,事先把这个区块的地图全部down下来,使用Sqlite数据库保存。留存。

 

//Task taskDown = new Task(DownTiles);
//taskDown.Start();

private void DownTiles()
        {
            double maxX = 138.796586;
            double maxY = 24.371022;
            double minX = 138.447725;
            double minY = 24.086215;
            double X0 = -180;
            double Y0 = 90;
            string tempUrl = "";
            HttpWebRequest req = null;
            Stream stream = null;

            int bufferLen = 1024 * 1024;
            int actual;
            byte[] buffer = new byte[bufferLen];

            for (int i = 9; i < 21; i++)//Level
            {
                int cmin = Math.Abs(Convert.ToInt32(Math.Floor((X0 - minX) / (256 * MapMethods.GetResoulution(i)))));
                int cmax = Math.Abs(Convert.ToInt32(Math.Floor((X0 - maxX) / (256 * MapMethods.GetResoulution(i)))));
                int rmin = Math.Abs(Convert.ToInt32(Math.Floor((Y0 - maxY) / (256 * MapMethods.GetResoulution(i)))));
                int rmax = Math.Abs(Convert.ToInt32(Math.Floor((Y0 - minY) / (256 * MapMethods.GetResoulution(i)))));
                for (int r = rmin; r < rmax; r++)//循环行
                {
                    for (int c = cmin; c < cmax; c++)//循环列
                    {
                        //Thread.Sleep(100);
                        tempUrl = GetTileUrl(i, r, c);
                        req = (HttpWebRequest)WebRequest.Create(tempUrl);
                        stream = req.GetResponse().GetResponseStream();



                        MemoryStream memoryStream = new MemoryStream();
                        
                        while ((actual = stream.Read(buffer, 0, bufferLen)) > 0)
                        {
                            memoryStream.Write(buffer, 0, actual);
                        }
                        memoryStream.Position = 0;

                        SaveTile(i, r, c, StreamToBytes2(memoryStream));
                        
                        
                    }
                }
            }
        }

        private byte[] StreamToBytes2(MemoryStream input)
        {
            byte[] bytes = new byte[input.Length];
            input.Read(bytes, 0, bytes.Length);
            return bytes;
        }

 

PGIS下载离线地图 SQLite+WPF

标签:

原文地址:http://www.cnblogs.com/lopengye/p/5065594.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!