谷歌瓦片地图纠偏

(地图瓦片纠偏最好的方法在这:https://www.cnblogs.com/s0611163/p/15606460.html)

    对谷歌瓦片地图进行纠偏,有两种方法:一是对拼接大图进行纠偏,然后重新切片;二是直接对瓦片图进行纠偏。这里我用的是第二种方法,即直接对瓦片地图进行纠偏。

App.config配置:

<appSettings>
  add key="inputPath" value="D:\_临时文件\GISMap\1818940751"/>
  ="outputPath"="D:\_临时文件\GISMapOutput\1818940751"="deltaPixcelX"="1031"="deltaPixcelY"="421"="fromMapZoom"="1"="toMapZoom"="18"/>
</>
View Code

对瓦片图进行纠偏处理的算法代码:

using System;
 System.Collections.Generic;
 System.ComponentModel;
 System.Configuration;
 System.Data;
 System.Drawing;
 System.IO;
 System.Linq;
 System.Text;
 System.Text.RegularExpressions;
 System.Threading;
 System.Threading.Tasks;
 System.Windows.Forms;
 Utils;

namespace TileProcess
{
    public partial class Form1 : Form
    {
        private int _count = 0;
        int _deltaPixcelX;
         _deltaPixcelY;
        string _inputPath;
         _outputPath;
         _fromMapZoom;
         _toMapZoom;

        private DateTime _startTime;
         _lastCount;

        public Form1()
        {
            InitializeComponent();

            _deltaPixcelX = Convert.ToInt32(ConfigurationManager.AppSettings["deltaPixcelX"]);
            _deltaPixcelY = Convert.ToInt32(ConfigurationManager.AppSettings[deltaPixcelY]);
            _inputPath = ConfigurationManager.AppSettings[inputPath];
            _outputPath = ConfigurationManager.AppSettings[outputPath];
            _fromMapZoom = Convert.ToInt32(ConfigurationManager.AppSettings[fromMapZoom]);
            _toMapZoom = Convert.ToInt32(ConfigurationManager.AppSettings[toMapZoom]);
        }

        void btnTileProcess_Click(object sender,EventArgs e)
        {
            this.btnTileProcess.Enabled = false;

            Task.Factory.StartNew(() =>
            {
                LogUtil.Log(开始处理);
                Process();
            });

            Thread thread = new Thread(new ThreadStart(() =>
            {
                int sleepInterval = 1000;
                while (true)
                {
                    Thread.Sleep(sleepInterval);
                    this.BeginInvoke(new Action(() =>
                    {
                        double totalSeconds = DateTime.Now.Subtract(_startTime).TotalSeconds;
                        int avg = (int)(_count / totalSeconds);
                        lblMsg.Text = string.Format(已处理 {0} 张瓦片图,_count);
                        if (_count - _lastCount > )
                        {
                            lblSpeed.Text = 当前速度:{0} 张/每秒,平均速度:{1} 张/每秒",(_count - _lastCount) * 1000.0 / sleepInterval,avg);
                        }
                        _lastCount = _count;
                    }));
                }
            }));
            thread.IsBackground = ;
            thread.Start();
        }

        /// <summary>
        /// 瓦片纠偏处理
        </summary>
        void Process()
        {
            _startTime = DateTime.Now;
            Regex regex = new Regex(@"\\(\d+)\\(\d+).pngfor (int i = _fromMapZoom; i <= _toMapZoom; i++)
            {
                int deltaPixcelX = (int)Math.Round(_deltaPixcelX / Math.Round(Math.Pow(2,18 - i)));
                int deltaPixcelY = (int)Math.Round(_deltaPixcelY / Math.Round(Math.Pow( i)));

                string[] fileArr = Directory.GetFiles(_inputPath + \\" + i,1)">*.*foreach (string file in fileArr)
                {
                    ThreadData data = new ThreadData();
                    data.File = file;
                    data.I = i;
                    data.DeltaPixcelX = deltaPixcelX;
                    data.DeltaPixcelY = deltaPixcelY;

                    ThreadUtil.Run((obj) =>
                    {
                        ThreadData d = obj as ThreadData;

                        Match match = regex.Match(d.File);
                        if (match.Success)
                        {
                            int x = Convert.ToInt32(match.Groups[1].Value);
                            int y = Convert.ToInt32(match.Groups[2].Value);

                            string pathTarget = string.Format({0}\{1}\{2}\{3}.pngif (!File.Exists(pathTarget))
                            {
                                Directory.Exists(Path.GetDirectoryName(pathTarget)))
                                {
                                    Directory.CreateDirectory(Path.GetDirectoryName(pathTarget));
                                }
                                Bitmap bmpNew = new Bitmap(256,1)">256 Graphics.FromImage(bmpNew);

                                int deltaX = data.DeltaPixcelX / ;
                                int deltaY = data.DeltaPixcelY / ;

                                //临时变量定义
                                string pathSource = null;
                                FileStream fs = byte[] bArr = ;
                                MemoryStream ms = ;
                                Bitmap bmpSource = 起始
                                pathSource =  deltaY);
                                 (File.Exists(pathSource))
                                {
                                    fs =  FileStream(pathSource,FileMode.Open,FileAccess.Read);
                                    bArr = new byte[fs.Length];
                                    int readCount = fs.Read(bArr,bArr.Length);
                                    ms = new MemoryStream(bArr,readCount);
                                    bmpSource =  Bitmap(ms);
                                    graph.DrawImage(bmpSource,0,new RectangleF(data.DeltaPixcelX % 256 - data.DeltaPixcelX % 256 - data.DeltaPixcelY % ),GraphicsUnit.Pixel);
                                    graph.Flush();

                                    fs.Close();
                                    fs = ;
                                    ms.Close();
                                    ms = ;
                                    bmpSource.Dispose();
                                    bmpSource = ;
                                }

                                
                                pathSource = 1,1)">new RectangleF(
                                pathSource = );
                                右下
                                pathSource = ;
                                }

                                bmpNew.Save(pathTarget);
                                bmpNew.Save("d:\\_临时文件\\1234.png"); 测试用

                                bmpNew.Dispose();
                                bmpNew = ;
                                graph.Dispose();
                                graph = ;

                                _count++;
                            } end if (!File.Exists(pathTarget))
                        } end if (match.Success)
                    },data,(ex) =>
                        {
                            lblErrorMsg.Text = 出错:" + ex.Message + \r\n" + ex.StackTrace;
                            LogUtil.LogError(ex,1)">出错);
                        }));
                    }); end ThreadUtil.Run
                } end foreach (string file in fileArr)
            } end for (int i = _fromMapZoom; i <= _toMapZoom; i++)
        }
    }
}
View Code

处理效率:我自己电脑每秒处理大约350张瓦片图,1到18级瓦片共100多万张图片,大约需要处理50分钟。

瓦片图纠偏前后对比:

 

还有另一种纠偏方法,通过修改leaflet源码进行纠偏:https://www.cnblogs.com/s0611163/p/13396622.html

 

相关文章

https://www.osgeo.cn/qgis-tutorial/overview.html https:...
设计方案是工程建设最关键的环节,也是影响城市规划的基本因...
BIM与GIS的区别与联系http://www.bimcn.org/cjwt/2018111516...
成功有感之给年轻人的10个忠告1、努力工作要努力,随随便便过...
鉴于陆地多边形为ShapelyMultiPolygon,我想找到代表例如多边...
背景与宣言传统的GISC/S开发已经很被别人不屑了,在时代的洪...