(地图瓦片纠偏最好的方法在这: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"/> </>
对瓦片图进行纠偏处理的算法代码:
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+).pngnoreCase); for (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)">256stem.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics graph = 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++) } } }
处理效率:我自己电脑每秒处理大约350张瓦片图,1到18级瓦片共100多万张图片,大约需要处理50分钟。
瓦片图纠偏前后对比:
还有另一种纠偏方法,通过修改leaflet源码进行纠偏:https://www.cnblogs.com/s0611163/p/13396622.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。