├── GMapDownLoad.sln ├── GMapDownLoad ├── App.config ├── DBHelper.cs ├── DiTu_DB.cs ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── GMapDownLoad.csproj ├── HttpHelper.cs ├── Log4Net.config ├── LogHelper.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── TitleClass.cs ├── dt.db └── packages.config ├── LICENSE └── README.md /GMapDownLoad.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.40629.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GMapDownLoad", "GMapDownLoad\GMapDownLoad.csproj", "{DABC98CA-8F4B-404F-AFB5-8DE392E7B87E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {DABC98CA-8F4B-404F-AFB5-8DE392E7B87E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {DABC98CA-8F4B-404F-AFB5-8DE392E7B87E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {DABC98CA-8F4B-404F-AFB5-8DE392E7B87E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {DABC98CA-8F4B-404F-AFB5-8DE392E7B87E}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /GMapDownLoad/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /GMapDownLoad/DBHelper.cs: -------------------------------------------------------------------------------- 1 | using CYQ.Data; 2 | using CYQ.Data.Table; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Data.SQLite; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace WindowsFormsApplication1 10 | { 11 | public class DBHelper 12 | { 13 | private static string ConnectStr = "Data Source=dt.db;failifmissing=false"; 14 | 15 | public static void SetDBPath(string name,string path) 16 | { 17 | ConnectStr = "Data Source=" + path + name + ".db;failifmissing=false"; 18 | } 19 | /// 20 | /// 检查目录下是否存在同名数据库,如不存在则创建,如存在则清空之前的数据 21 | /// 22 | /// 23 | /// 24 | /// 25 | public static bool CheckDB(string name,string path) 26 | { 27 | SetDBPath(name, path); 28 | 29 | string sql = "DROP TABLE IF EXISTS \"dt\";CREATE TABLE \"dt\" (\"id\" TEXT NOT NULL,\"z\" INTEGER DEFAULT 0,\"x\" INTEGER DEFAULT 0,\"y\" INTEGER DEFAULT 0,\"d\" INTEGER DEFAULT 0,PRIMARY KEY (\"id\")); "; 30 | 31 | using (MProc proc = new MProc(sql, ConnectStr)) 32 | { 33 | int result = proc.ExeNonQuery(); 34 | 35 | return result >= 0; 36 | } 37 | } 38 | 39 | /// 40 | /// 批量向数据库写入瓦片数据xyz信息 41 | /// 42 | /// 43 | /// 44 | public static bool insertDatas(List listdata) 45 | { 46 | using(MDataTable dt2 = MDataTable.CreateFrom(listdata)) 47 | { 48 | dt2.TableName = TableNames.dt.ToString(); 49 | 50 | dt2.Conn = ConnectStr; 51 | 52 | return dt2.AcceptChanges(AcceptOp.InsertWithID); 53 | } 54 | } 55 | 56 | 57 | public static bool insertDatasNew(List listdata) 58 | { 59 | using (SQLiteConnection conn = new SQLiteConnection(ConnectStr)) 60 | { 61 | conn.Open(); 62 | SQLiteCommand cmd = new SQLiteCommand(); 63 | cmd.Connection = conn; 64 | SQLiteTransaction tx = conn.BeginTransaction(); 65 | cmd.Transaction = tx; 66 | try 67 | { 68 | foreach (DiTu_DB item in listdata) 69 | { 70 | string strsql = item.GetInsertString(); 71 | if (strsql.Trim().Length > 1) 72 | { 73 | cmd.CommandText = strsql; 74 | cmd.ExecuteNonQuery(); 75 | } 76 | } 77 | tx.Commit(); 78 | } 79 | catch (System.Data.SQLite.SQLiteException E) 80 | { 81 | tx.Rollback(); 82 | return false; 83 | } 84 | } 85 | return true; 86 | } 87 | 88 | /// 89 | /// 批量更新瓦片数据 90 | /// 91 | /// 92 | /// 93 | public static bool updateDatas(List listdata) 94 | { 95 | using (MDataTable dt2 = MDataTable.CreateFrom(listdata)) 96 | { 97 | dt2.SetState(2); 98 | 99 | dt2.TableName = TableNames.dt.ToString(); 100 | 101 | dt2.Conn = ConnectStr; 102 | 103 | return dt2.AcceptChanges(AcceptOp.Update); 104 | } 105 | } 106 | 107 | /// 108 | /// 更新某一个瓦片数据的标记位 109 | /// 110 | /// 111 | /// 112 | /// 113 | /// 114 | /// 115 | public static bool updateItem(int x,int y,int z,int d) 116 | { 117 | using (MAction action = new MAction(TableNames.dt, ConnectStr)) 118 | { 119 | action.Set(dt.d, d); 120 | string whereStr = "x=" + x + " and y=" + y + " and z=" + z; 121 | return action.Update(whereStr); 122 | } 123 | } 124 | 125 | /// 126 | /// 根据标记位从库中获取一定数量的数据 127 | /// 128 | /// 129 | /// 130 | /// 131 | public static List GetData(int count,int dataflag) 132 | { 133 | using (MAction action = new MAction(TableNames.dt, ConnectStr)) 134 | { 135 | string whereStr = "d=" + dataflag + " LIMIT " + count; 136 | MDataTable rs = action.Select(whereStr); 137 | 138 | return rs.ToList(); 139 | } 140 | } 141 | 142 | /// 143 | /// 库中未处理的数据的数量 144 | /// 145 | /// 146 | /// 147 | /// 148 | public static int isComplate(Form1 fm, int dataflag) 149 | { 150 | string sql = "SELECT count(*) FROM dt WHERE d=" + dataflag; 151 | 152 | using (MProc proc = new MProc(sql, ConnectStr)) 153 | { 154 | int result = proc.ExeScalar(); 155 | if (fm != null) 156 | { 157 | fm.showLable4(result.ToString()); 158 | } 159 | return result; 160 | } 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /GMapDownLoad/DiTu_DB.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | namespace WindowsFormsApplication1 6 | { 7 | public enum TableNames { dt } 8 | 9 | #region 枚举 10 | public enum dt { id, z, x, y, d } 11 | #endregion 12 | 13 | public class DiTu_DB 14 | { 15 | private string _id; 16 | public string id 17 | { 18 | get 19 | { 20 | return _id; 21 | } 22 | set 23 | { 24 | _id = value; 25 | } 26 | } 27 | 28 | private int _z; 29 | public int z 30 | { 31 | get 32 | { 33 | return _z; 34 | } 35 | set 36 | { 37 | _z = value; 38 | } 39 | } 40 | private int _x; 41 | public int x 42 | { 43 | get 44 | { 45 | return _x; 46 | } 47 | set 48 | { 49 | _x = value; 50 | } 51 | } 52 | private int _y; 53 | public int y 54 | { 55 | get 56 | { 57 | return _y; 58 | } 59 | set 60 | { 61 | _y = value; 62 | } 63 | } 64 | private int _d; 65 | public int d 66 | { 67 | get 68 | { 69 | return _d; 70 | } 71 | set 72 | { 73 | _d = value; 74 | } 75 | } 76 | 77 | private const String insertSqlTem = "INSERT INTO dt (id,x,y,z) VALUES ({0},{1},{2},{3})"; 78 | 79 | public string GetInsertString() 80 | { 81 | return string.Format(insertSqlTem, id, x, y, z); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /GMapDownLoad/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace WindowsFormsApplication1 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | /// 如果应释放托管资源,为 true;否则为 false。 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows 窗体设计器生成的代码 24 | 25 | /// 26 | /// 设计器支持所需的方法 - 不要 27 | /// 使用代码编辑器修改此方法的内容。 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.components = new System.ComponentModel.Container(); 32 | this.textBox_dic = new System.Windows.Forms.TextBox(); 33 | this.button_init = new System.Windows.Forms.Button(); 34 | this.label1 = new System.Windows.Forms.Label(); 35 | this.label2 = new System.Windows.Forms.Label(); 36 | this.textBox_name = new System.Windows.Forms.TextBox(); 37 | this.button_start = new System.Windows.Forms.Button(); 38 | this.label3 = new System.Windows.Forms.Label(); 39 | this.timer1 = new System.Windows.Forms.Timer(this.components); 40 | this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); 41 | this.label4 = new System.Windows.Forms.Label(); 42 | this.label5 = new System.Windows.Forms.Label(); 43 | this.label6 = new System.Windows.Forms.Label(); 44 | this.label7 = new System.Windows.Forms.Label(); 45 | this.label8 = new System.Windows.Forms.Label(); 46 | this.textBox_s_lon = new System.Windows.Forms.TextBox(); 47 | this.textBox_s_lat = new System.Windows.Forms.TextBox(); 48 | this.textBox_e_lon = new System.Windows.Forms.TextBox(); 49 | this.textBox_e_lat = new System.Windows.Forms.TextBox(); 50 | this.groupBox1 = new System.Windows.Forms.GroupBox(); 51 | this.button_selectDic = new System.Windows.Forms.Button(); 52 | this.label9 = new System.Windows.Forms.Label(); 53 | this.label10 = new System.Windows.Forms.Label(); 54 | this.groupBox2 = new System.Windows.Forms.GroupBox(); 55 | this.textBox_error_down = new System.Windows.Forms.TextBox(); 56 | this.textBox_complate_down = new System.Windows.Forms.TextBox(); 57 | this.textBox_need_down = new System.Windows.Forms.TextBox(); 58 | this.label11 = new System.Windows.Forms.Label(); 59 | this.label12 = new System.Windows.Forms.Label(); 60 | this.numericUpDownSZ = new System.Windows.Forms.NumericUpDown(); 61 | this.label13 = new System.Windows.Forms.Label(); 62 | this.numericUpDownEZ = new System.Windows.Forms.NumericUpDown(); 63 | this.textBox1 = new System.Windows.Forms.TextBox(); 64 | this.groupBox1.SuspendLayout(); 65 | this.groupBox2.SuspendLayout(); 66 | ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSZ)).BeginInit(); 67 | ((System.ComponentModel.ISupportInitialize)(this.numericUpDownEZ)).BeginInit(); 68 | this.SuspendLayout(); 69 | // 70 | // textBox_dic 71 | // 72 | this.textBox_dic.Location = new System.Drawing.Point(74, 21); 73 | this.textBox_dic.Name = "textBox_dic"; 74 | this.textBox_dic.Size = new System.Drawing.Size(340, 21); 75 | this.textBox_dic.TabIndex = 0; 76 | // 77 | // button_init 78 | // 79 | this.button_init.Location = new System.Drawing.Point(12, 310); 80 | this.button_init.Name = "button_init"; 81 | this.button_init.Size = new System.Drawing.Size(110, 23); 82 | this.button_init.TabIndex = 5; 83 | this.button_init.Text = "1.初始化任务"; 84 | this.button_init.UseVisualStyleBackColor = true; 85 | this.button_init.Click += new System.EventHandler(this.button2_Click); 86 | // 87 | // label1 88 | // 89 | this.label1.AutoSize = true; 90 | this.label1.Location = new System.Drawing.Point(15, 24); 91 | this.label1.Name = "label1"; 92 | this.label1.Size = new System.Drawing.Size(53, 12); 93 | this.label1.TabIndex = 3; 94 | this.label1.Text = "存储位置"; 95 | // 96 | // label2 97 | // 98 | this.label2.AutoSize = true; 99 | this.label2.Location = new System.Drawing.Point(15, 59); 100 | this.label2.Name = "label2"; 101 | this.label2.Size = new System.Drawing.Size(53, 12); 102 | this.label2.TabIndex = 4; 103 | this.label2.Text = "任务名称"; 104 | // 105 | // textBox_name 106 | // 107 | this.textBox_name.Location = new System.Drawing.Point(74, 56); 108 | this.textBox_name.Name = "textBox_name"; 109 | this.textBox_name.Size = new System.Drawing.Size(340, 21); 110 | this.textBox_name.TabIndex = 2; 111 | // 112 | // button_start 113 | // 114 | this.button_start.Location = new System.Drawing.Point(153, 310); 115 | this.button_start.Name = "button_start"; 116 | this.button_start.Size = new System.Drawing.Size(93, 23); 117 | this.button_start.TabIndex = 6; 118 | this.button_start.Text = "2.下载数据"; 119 | this.button_start.UseVisualStyleBackColor = true; 120 | this.button_start.Click += new System.EventHandler(this.button3_Click); 121 | // 122 | // label3 123 | // 124 | this.label3.AutoSize = true; 125 | this.label3.Location = new System.Drawing.Point(15, 350); 126 | this.label3.Name = "label3"; 127 | this.label3.Size = new System.Drawing.Size(53, 12); 128 | this.label3.TabIndex = 7; 129 | this.label3.Text = "完成进度"; 130 | // 131 | // timer1 132 | // 133 | this.timer1.Interval = 2000; 134 | this.timer1.Tick += new System.EventHandler(this.timer1_Tick); 135 | // 136 | // backgroundWorker1 137 | // 138 | this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork); 139 | // 140 | // label4 141 | // 142 | this.label4.AutoSize = true; 143 | this.label4.Location = new System.Drawing.Point(15, 377); 144 | this.label4.Name = "label4"; 145 | this.label4.Size = new System.Drawing.Size(53, 12); 146 | this.label4.TabIndex = 8; 147 | this.label4.Text = "剩余数据"; 148 | // 149 | // label5 150 | // 151 | this.label5.AutoSize = true; 152 | this.label5.Location = new System.Drawing.Point(15, 30); 153 | this.label5.Name = "label5"; 154 | this.label5.Size = new System.Drawing.Size(53, 12); 155 | this.label5.TabIndex = 9; 156 | this.label5.Text = "起始经度"; 157 | // 158 | // label6 159 | // 160 | this.label6.AutoSize = true; 161 | this.label6.Location = new System.Drawing.Point(15, 67); 162 | this.label6.Name = "label6"; 163 | this.label6.Size = new System.Drawing.Size(53, 12); 164 | this.label6.TabIndex = 10; 165 | this.label6.Text = "起始纬度"; 166 | // 167 | // label7 168 | // 169 | this.label7.AutoSize = true; 170 | this.label7.Location = new System.Drawing.Point(15, 101); 171 | this.label7.Name = "label7"; 172 | this.label7.Size = new System.Drawing.Size(53, 12); 173 | this.label7.TabIndex = 11; 174 | this.label7.Text = "结束经度"; 175 | // 176 | // label8 177 | // 178 | this.label8.AutoSize = true; 179 | this.label8.Location = new System.Drawing.Point(15, 138); 180 | this.label8.Name = "label8"; 181 | this.label8.Size = new System.Drawing.Size(53, 12); 182 | this.label8.TabIndex = 12; 183 | this.label8.Text = "结束纬度"; 184 | // 185 | // textBox_s_lon 186 | // 187 | this.textBox_s_lon.Location = new System.Drawing.Point(74, 27); 188 | this.textBox_s_lon.Name = "textBox_s_lon"; 189 | this.textBox_s_lon.Size = new System.Drawing.Size(143, 21); 190 | this.textBox_s_lon.TabIndex = 0; 191 | this.textBox_s_lon.Text = "-175"; 192 | // 193 | // textBox_s_lat 194 | // 195 | this.textBox_s_lat.Location = new System.Drawing.Point(74, 64); 196 | this.textBox_s_lat.Name = "textBox_s_lat"; 197 | this.textBox_s_lat.Size = new System.Drawing.Size(143, 21); 198 | this.textBox_s_lat.TabIndex = 1; 199 | this.textBox_s_lat.Text = "-80"; 200 | // 201 | // textBox_e_lon 202 | // 203 | this.textBox_e_lon.Location = new System.Drawing.Point(74, 98); 204 | this.textBox_e_lon.Name = "textBox_e_lon"; 205 | this.textBox_e_lon.Size = new System.Drawing.Size(143, 21); 206 | this.textBox_e_lon.TabIndex = 2; 207 | this.textBox_e_lon.Text = "175"; 208 | // 209 | // textBox_e_lat 210 | // 211 | this.textBox_e_lat.Location = new System.Drawing.Point(74, 135); 212 | this.textBox_e_lat.Name = "textBox_e_lat"; 213 | this.textBox_e_lat.Size = new System.Drawing.Size(143, 21); 214 | this.textBox_e_lat.TabIndex = 3; 215 | this.textBox_e_lat.Text = "80"; 216 | // 217 | // groupBox1 218 | // 219 | this.groupBox1.Controls.Add(this.numericUpDownEZ); 220 | this.groupBox1.Controls.Add(this.label13); 221 | this.groupBox1.Controls.Add(this.numericUpDownSZ); 222 | this.groupBox1.Controls.Add(this.label12); 223 | this.groupBox1.Controls.Add(this.textBox_s_lat); 224 | this.groupBox1.Controls.Add(this.textBox_e_lat); 225 | this.groupBox1.Controls.Add(this.label5); 226 | this.groupBox1.Controls.Add(this.textBox_e_lon); 227 | this.groupBox1.Controls.Add(this.label6); 228 | this.groupBox1.Controls.Add(this.label7); 229 | this.groupBox1.Controls.Add(this.textBox_s_lon); 230 | this.groupBox1.Controls.Add(this.label8); 231 | this.groupBox1.Location = new System.Drawing.Point(12, 100); 232 | this.groupBox1.Name = "groupBox1"; 233 | this.groupBox1.Size = new System.Drawing.Size(234, 204); 234 | this.groupBox1.TabIndex = 3; 235 | this.groupBox1.TabStop = false; 236 | this.groupBox1.Text = "数据范围"; 237 | // 238 | // button_selectDic 239 | // 240 | this.button_selectDic.Location = new System.Drawing.Point(420, 19); 241 | this.button_selectDic.Name = "button_selectDic"; 242 | this.button_selectDic.Size = new System.Drawing.Size(34, 23); 243 | this.button_selectDic.TabIndex = 1; 244 | this.button_selectDic.Text = "..."; 245 | this.button_selectDic.UseVisualStyleBackColor = true; 246 | this.button_selectDic.Click += new System.EventHandler(this.button_selectDic_Click); 247 | // 248 | // label9 249 | // 250 | this.label9.AutoSize = true; 251 | this.label9.Location = new System.Drawing.Point(22, 39); 252 | this.label9.Name = "label9"; 253 | this.label9.Size = new System.Drawing.Size(89, 12); 254 | this.label9.TabIndex = 19; 255 | this.label9.Text = "需下载数据标记"; 256 | // 257 | // label10 258 | // 259 | this.label10.AutoSize = true; 260 | this.label10.Location = new System.Drawing.Point(22, 83); 261 | this.label10.Name = "label10"; 262 | this.label10.Size = new System.Drawing.Size(89, 12); 263 | this.label10.TabIndex = 20; 264 | this.label10.Text = "下载完成后标记"; 265 | // 266 | // groupBox2 267 | // 268 | this.groupBox2.Controls.Add(this.textBox_error_down); 269 | this.groupBox2.Controls.Add(this.label10); 270 | this.groupBox2.Controls.Add(this.textBox_complate_down); 271 | this.groupBox2.Controls.Add(this.label9); 272 | this.groupBox2.Controls.Add(this.textBox_need_down); 273 | this.groupBox2.Controls.Add(this.label11); 274 | this.groupBox2.Location = new System.Drawing.Point(272, 100); 275 | this.groupBox2.Name = "groupBox2"; 276 | this.groupBox2.Size = new System.Drawing.Size(245, 172); 277 | this.groupBox2.TabIndex = 4; 278 | this.groupBox2.TabStop = false; 279 | this.groupBox2.Text = "多次下载标记设置"; 280 | // 281 | // textBox_error_down 282 | // 283 | this.textBox_error_down.Location = new System.Drawing.Point(125, 129); 284 | this.textBox_error_down.Name = "textBox_error_down"; 285 | this.textBox_error_down.Size = new System.Drawing.Size(100, 21); 286 | this.textBox_error_down.TabIndex = 2; 287 | this.textBox_error_down.Text = "2"; 288 | // 289 | // textBox_complate_down 290 | // 291 | this.textBox_complate_down.Location = new System.Drawing.Point(125, 80); 292 | this.textBox_complate_down.Name = "textBox_complate_down"; 293 | this.textBox_complate_down.Size = new System.Drawing.Size(100, 21); 294 | this.textBox_complate_down.TabIndex = 1; 295 | this.textBox_complate_down.Text = "1"; 296 | // 297 | // textBox_need_down 298 | // 299 | this.textBox_need_down.Location = new System.Drawing.Point(125, 36); 300 | this.textBox_need_down.Name = "textBox_need_down"; 301 | this.textBox_need_down.Size = new System.Drawing.Size(100, 21); 302 | this.textBox_need_down.TabIndex = 0; 303 | this.textBox_need_down.Text = "0"; 304 | // 305 | // label11 306 | // 307 | this.label11.AutoSize = true; 308 | this.label11.Location = new System.Drawing.Point(22, 132); 309 | this.label11.Name = "label11"; 310 | this.label11.Size = new System.Drawing.Size(77, 12); 311 | this.label11.TabIndex = 22; 312 | this.label11.Text = "下载错误标记"; 313 | // 314 | // label12 315 | // 316 | this.label12.AutoSize = true; 317 | this.label12.Location = new System.Drawing.Point(15, 170); 318 | this.label12.Name = "label12"; 319 | this.label12.Size = new System.Drawing.Size(35, 12); 320 | this.label12.TabIndex = 17; 321 | this.label12.Text = "Z范围"; 322 | // 323 | // numericUpDownSZ 324 | // 325 | this.numericUpDownSZ.Location = new System.Drawing.Point(74, 167); 326 | this.numericUpDownSZ.Maximum = new decimal(new int[] { 327 | 22, 328 | 0, 329 | 0, 330 | 0}); 331 | this.numericUpDownSZ.Name = "numericUpDownSZ"; 332 | this.numericUpDownSZ.Size = new System.Drawing.Size(44, 21); 333 | this.numericUpDownSZ.TabIndex = 4; 334 | // 335 | // label13 336 | // 337 | this.label13.AutoSize = true; 338 | this.label13.Location = new System.Drawing.Point(124, 170); 339 | this.label13.Name = "label13"; 340 | this.label13.Size = new System.Drawing.Size(23, 12); 341 | this.label13.TabIndex = 19; 342 | this.label13.Text = "---"; 343 | // 344 | // numericUpDownEZ 345 | // 346 | this.numericUpDownEZ.Location = new System.Drawing.Point(153, 167); 347 | this.numericUpDownEZ.Maximum = new decimal(new int[] { 348 | 22, 349 | 0, 350 | 0, 351 | 0}); 352 | this.numericUpDownEZ.Name = "numericUpDownEZ"; 353 | this.numericUpDownEZ.Size = new System.Drawing.Size(43, 21); 354 | this.numericUpDownEZ.TabIndex = 5; 355 | this.numericUpDownEZ.Value = new decimal(new int[] { 356 | 19, 357 | 0, 358 | 0, 359 | 0}); 360 | // 361 | // textBox1 362 | // 363 | this.textBox1.Location = new System.Drawing.Point(271, 292); 364 | this.textBox1.Multiline = true; 365 | this.textBox1.Name = "textBox1"; 366 | this.textBox1.ReadOnly = true; 367 | this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; 368 | this.textBox1.Size = new System.Drawing.Size(246, 106); 369 | this.textBox1.TabIndex = 22; 370 | // 371 | // Form1 372 | // 373 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 374 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 375 | this.ClientSize = new System.Drawing.Size(549, 410); 376 | this.Controls.Add(this.textBox1); 377 | this.Controls.Add(this.groupBox2); 378 | this.Controls.Add(this.button_selectDic); 379 | this.Controls.Add(this.groupBox1); 380 | this.Controls.Add(this.label4); 381 | this.Controls.Add(this.label3); 382 | this.Controls.Add(this.button_start); 383 | this.Controls.Add(this.textBox_name); 384 | this.Controls.Add(this.label2); 385 | this.Controls.Add(this.label1); 386 | this.Controls.Add(this.button_init); 387 | this.Controls.Add(this.textBox_dic); 388 | this.Name = "Form1"; 389 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 390 | this.Text = "Form1"; 391 | this.Load += new System.EventHandler(this.Form1_Load); 392 | this.groupBox1.ResumeLayout(false); 393 | this.groupBox1.PerformLayout(); 394 | this.groupBox2.ResumeLayout(false); 395 | this.groupBox2.PerformLayout(); 396 | ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSZ)).EndInit(); 397 | ((System.ComponentModel.ISupportInitialize)(this.numericUpDownEZ)).EndInit(); 398 | this.ResumeLayout(false); 399 | this.PerformLayout(); 400 | 401 | } 402 | 403 | #endregion 404 | 405 | private System.Windows.Forms.TextBox textBox_dic; 406 | private System.Windows.Forms.Button button_init; 407 | private System.Windows.Forms.Label label1; 408 | private System.Windows.Forms.Label label2; 409 | private System.Windows.Forms.TextBox textBox_name; 410 | private System.Windows.Forms.Button button_start; 411 | private System.Windows.Forms.Label label3; 412 | private System.Windows.Forms.Timer timer1; 413 | private System.ComponentModel.BackgroundWorker backgroundWorker1; 414 | private System.Windows.Forms.Label label4; 415 | private System.Windows.Forms.Label label5; 416 | private System.Windows.Forms.Label label6; 417 | private System.Windows.Forms.Label label7; 418 | private System.Windows.Forms.Label label8; 419 | private System.Windows.Forms.TextBox textBox_s_lon; 420 | private System.Windows.Forms.TextBox textBox_s_lat; 421 | private System.Windows.Forms.TextBox textBox_e_lon; 422 | private System.Windows.Forms.TextBox textBox_e_lat; 423 | private System.Windows.Forms.GroupBox groupBox1; 424 | private System.Windows.Forms.Button button_selectDic; 425 | private System.Windows.Forms.Label label9; 426 | private System.Windows.Forms.Label label10; 427 | private System.Windows.Forms.GroupBox groupBox2; 428 | private System.Windows.Forms.TextBox textBox_error_down; 429 | private System.Windows.Forms.TextBox textBox_complate_down; 430 | private System.Windows.Forms.TextBox textBox_need_down; 431 | private System.Windows.Forms.Label label11; 432 | private System.Windows.Forms.NumericUpDown numericUpDownEZ; 433 | private System.Windows.Forms.Label label13; 434 | private System.Windows.Forms.NumericUpDown numericUpDownSZ; 435 | private System.Windows.Forms.Label label12; 436 | private System.Windows.Forms.TextBox textBox1; 437 | } 438 | } 439 | 440 | -------------------------------------------------------------------------------- /GMapDownLoad/Form1.cs: -------------------------------------------------------------------------------- 1 | using DotNet.Utilities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Drawing; 7 | using System.Linq; 8 | using System.Net; 9 | using System.Text; 10 | using System.Windows.Forms; 11 | 12 | namespace WindowsFormsApplication1 13 | { 14 | public partial class Form1 : Form 15 | { 16 | public Form1() 17 | { 18 | InitializeComponent(); 19 | } 20 | 21 | //经纬度信息 22 | double lon1, lat1, lon2, lat2; 23 | int zmin=0; 24 | int zmax=19; 25 | 26 | //数据下载时的标志 27 | int needflag = 0; 28 | int complateflag = 1; 29 | int errorflag = 2; 30 | 31 | Random rd = new Random(); 32 | //谷歌中国卫星地图,有偏移[0123] 33 | string baseurl = "http://mt{3}.google.cn/maps/vt?lyrs=s%40773&hl=zh-CN&gl=CN&x={0}&y={1}&z={2}"; 34 | //谷歌卫星影像,无偏移[0123] 35 | //string baseurl = "http://khm{3}.google.com/kh/v=762&hl=zh&x={0}&y={1}&z={2}&s="; 36 | //基础路径 37 | string basepath = @"F:/osgearth/data/csharp/wuqi/"; 38 | //基础名称 39 | string basename = "dt"; 40 | 41 | /// 42 | /// 获取输入的经纬度 43 | /// 44 | /// 45 | private bool initLonlat() 46 | { 47 | //西安 48 | //lon1 = 108.809959; 49 | //lat1 = 34.152847; 50 | //lon2 = 109.078258; 51 | //lat2 = 34.376046; 52 | 53 | //吴起县 54 | //lon1 = 108.562113; 55 | //lat1 = 37.419379; 56 | //lon2 = 107.649612; 57 | //lat2 = 36.551149; 58 | try 59 | { 60 | lon1 = double.Parse(this.textBox_s_lon.Text); 61 | lat1 = double.Parse(this.textBox_s_lat.Text); 62 | lon2 = double.Parse(this.textBox_e_lon.Text); 63 | lat2 = double.Parse(this.textBox_e_lat.Text); 64 | return true; 65 | } 66 | catch (Exception ex) 67 | { 68 | return false; 69 | } 70 | } 71 | 72 | /// 73 | /// 获取并检查输入的基础路径是否存在 74 | /// 75 | /// 76 | private bool chackBasePath() 77 | { 78 | basename = this.textBox_name.Text; 79 | basepath = this.textBox_dic.Text; 80 | if (System.IO.Directory.Exists(basepath) && string.IsNullOrWhiteSpace(basename)==false) 81 | { 82 | if (basepath[basepath.Length - 1] != '\\' || basepath[basepath.Length - 1] != '/') 83 | { 84 | basepath += @"\"; 85 | } 86 | return true; 87 | } 88 | return false; 89 | } 90 | 91 | /// 92 | /// 检查输入的标识是否合法 93 | /// 94 | /// 95 | private bool CheckFlag() 96 | { 97 | try 98 | { 99 | needflag = int.Parse(this.textBox_need_down.Text); 100 | complateflag = int.Parse(this.textBox_complate_down.Text); 101 | errorflag = int.Parse(this.textBox_error_down.Text); 102 | return true; 103 | } 104 | catch (Exception ex) 105 | { 106 | return false; 107 | } 108 | } 109 | 110 | /// 111 | /// 通过给定的瓦片序号构造瓦片数据地址 112 | /// 113 | /// 114 | /// 115 | /// 116 | /// 117 | private string GetTileUrl(int x, int y, int z) 118 | { 119 | return string.Format(baseurl, x, y, z,rd.Next(0,4)); 120 | } 121 | 122 | /// 123 | /// 检查路径是否存在,如不存在则创建 124 | /// 125 | /// 126 | private void CheckPath(string path) 127 | { 128 | if (!System.IO.Directory.Exists(path)) 129 | { 130 | System.IO.Directory.CreateDirectory(path); 131 | } 132 | } 133 | 134 | /// 135 | /// 检查输入的层级索引是否正确 136 | /// 137 | /// 138 | private bool CheckZindex() 139 | { 140 | zmin = (int)this.numericUpDownSZ.Value; 141 | zmax = (int)this.numericUpDownEZ.Value; 142 | if (zmax < zmin) 143 | { 144 | return false; 145 | } 146 | return true; 147 | } 148 | 149 | private void button2_Click(object sender, EventArgs e) 150 | { 151 | if (chackBasePath() == false) 152 | { 153 | MessageBox.Show("输入的路径不存在或名称为空"); 154 | return; 155 | } 156 | if (initLonlat() == false) 157 | { 158 | MessageBox.Show("输入的经纬度数据不正确"); 159 | return; 160 | } 161 | if (CheckFlag() == false) 162 | { 163 | MessageBox.Show("输入的标记位数据不正确"); 164 | return; 165 | } 166 | if (CheckZindex() == false) 167 | { 168 | MessageBox.Show("Z索引输入有误"); 169 | return; 170 | } 171 | 172 | long countsum = 0; 173 | 174 | //检查并初始化数据库 175 | DBHelper.CheckDB(basename,basepath); 176 | 177 | List listdata = new List(); 178 | //根据坐标计算每一级别的tmsXY 179 | for (int z = zmin; z <= zmax; ++z) 180 | { 181 | //通过经纬度和层级计算tile坐标 182 | Point tmstemp1 = TitleClass.WorldToTilePosP(lon1, lat1, z); 183 | Point tmstemp2 = TitleClass.WorldToTilePosP(lon2, lat2, z); 184 | 185 | Point tmsmax = new Point(Math.Max(tmstemp1.X, tmstemp2.X), Math.Max(tmstemp1.Y, tmstemp2.Y)); 186 | Point tmsmin = new Point(Math.Min(tmstemp1.X, tmstemp2.X), Math.Min(tmstemp1.Y, tmstemp2.Y)); 187 | 188 | 189 | //循环构造tile数据信息,创建相应目录并把tile的xyz写入数据库 190 | string zpath = basepath + z + @"\"; 191 | for (int x = tmsmin.X; x < tmsmax.X + 1; ++x) 192 | { 193 | string xpath = zpath + x + @"\"; 194 | CheckPath(xpath); 195 | for (int y = tmsmin.Y; y < tmsmax.Y + 1; ++y) 196 | { 197 | countsum++; 198 | DiTu_DB dobj = new DiTu_DB(); 199 | dobj.id = x.ToString() + y.ToString() + z.ToString(); 200 | dobj.x = x; 201 | dobj.y = y; 202 | dobj.z = z; 203 | dobj.d = 0; 204 | 205 | listdata.Add(dobj); 206 | if (listdata.Count > 500000) 207 | { 208 | DBHelper.insertDatasNew(listdata); 209 | listdata.Clear(); 210 | } 211 | } 212 | } 213 | } 214 | 215 | DBHelper.insertDatas(listdata); 216 | 217 | this.button_init.Text = "已完成" + countsum.ToString(); 218 | listdata.Clear(); 219 | } 220 | 221 | private void button3_Click(object sender, EventArgs e) 222 | { 223 | if (chackBasePath() == false) 224 | { 225 | MessageBox.Show("输入的路径不存在或名称为空"); 226 | return; 227 | } 228 | if (CheckFlag() == false) 229 | { 230 | MessageBox.Show("输入的标记位数据不正确"); 231 | return; 232 | } 233 | 234 | if (chackBasePath() == false) 235 | { 236 | MessageBox.Show("输入的路径不存在或名称为空"); 237 | return; 238 | } 239 | 240 | DBHelper.SetDBPath(basename, basepath); 241 | 242 | timer1.Start(); 243 | 244 | backgroundWorker1.RunWorkerAsync(); 245 | 246 | this.button_init.Enabled = false; 247 | 248 | this.button_selectDic.Enabled = false; 249 | 250 | this.button_start.Enabled = false; 251 | } 252 | 253 | int allCount = 0; 254 | int timeCount = 0; 255 | 256 | private void AddAllCount() 257 | { 258 | timeCount++; 259 | if (label3.InvokeRequired) 260 | { 261 | label3.BeginInvoke( 262 | new Action(() => 263 | { 264 | label3.Text = "已完成" + allCount + "次,耗时" + timeCount * timer1.Interval / 1000 + "秒"; 265 | }) 266 | ); 267 | } 268 | else 269 | { 270 | label3.Text = "已完成" + allCount + "次,耗时" + timeCount * timer1.Interval / 1000 + "秒"; 271 | } 272 | } 273 | 274 | public void showLable4(string info) 275 | { 276 | if (label4.InvokeRequired) 277 | { 278 | label4.BeginInvoke( 279 | new Action(() => 280 | { 281 | label4.Text = info; 282 | }) 283 | ); 284 | } 285 | else 286 | { 287 | label4.Text = info; 288 | } 289 | } 290 | 291 | private void timer1_Tick(object sender, EventArgs e) 292 | { 293 | AddAllCount(); 294 | } 295 | 296 | /// 297 | /// 数据下载的线程 298 | /// 299 | /// 300 | /// 301 | private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) 302 | { 303 | //检查数据库中是否还有需要下载的数据 304 | while (DBHelper.isComplate(this, needflag) != 0) 305 | { 306 | //从需要下载的数据中取出10000个数据 307 | List datas = DBHelper.GetData(10000,needflag); 308 | 309 | //对这10000个数据进行并行处理 310 | System.Threading.Tasks.Parallel.For(0, datas.Count, (int i) => 311 | { 312 | //构造下载数据的保存路径 313 | string path = basepath + datas[i].z + @"\" + datas[i].x + @"\" + datas[i].y + ".jpg"; 314 | //构造下载地址 315 | string url = GetTileUrl(datas[i].x, datas[i].y, datas[i].z); 316 | //下载数据 317 | try 318 | { 319 | using (WebClient webClient = new WebClient()) 320 | { 321 | webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36"); 322 | webClient.Headers.Add("Accept", "image/webp,image/apng,image/*,*/*;q=0.8"); 323 | webClient.Headers.Add("Accept-Encoding", "gzip, deflate"); 324 | webClient.Headers.Add("Accept-Language", "zh-CN,zh;q=0.9"); 325 | webClient.Headers.Add("Referer", "http://www.361.me/"); 326 | webClient.DownloadFile(url, path); 327 | } 328 | //检查是否下载完成及下载的文件是否合法,并更新数据标记位 329 | if (System.IO.File.Exists(path)) 330 | { 331 | System.IO.FileInfo fileInfo = new System.IO.FileInfo(path); 332 | if (fileInfo.Length > 0) 333 | { 334 | datas[i].d = complateflag; 335 | } 336 | else 337 | { 338 | datas[i].d = errorflag; 339 | } 340 | } 341 | else 342 | { 343 | datas[i].d = errorflag; 344 | } 345 | } 346 | catch (Exception ex) 347 | { 348 | LogHelper.WriteLog(url + "\t" + ex.Message); 349 | //Console.WriteLine(url + "\t" + ex.Message); 350 | if (datas[i].d != complateflag) 351 | { 352 | datas[i].d = errorflag; 353 | } 354 | } 355 | //原子操作计数器 356 | System.Threading.Interlocked.Increment(ref allCount); 357 | } 358 | ); 359 | //批量更新已下载数据的标记位 360 | DBHelper.updateDatas(datas); 361 | } 362 | 363 | timer1.Stop(); 364 | 365 | this.button_init.Enabled = true; 366 | 367 | this.button_selectDic.Enabled = true; 368 | 369 | this.button_start.Enabled = true; 370 | } 371 | 372 | private void button_selectDic_Click(object sender, EventArgs e) 373 | { 374 | FolderBrowserDialog P_File_Folder = new FolderBrowserDialog(); 375 | 376 | if (P_File_Folder.ShowDialog() == DialogResult.OK) 377 | { 378 | this.textBox_dic.Text = P_File_Folder.SelectedPath; 379 | } 380 | } 381 | 382 | private void Form1_Load(object sender, EventArgs e) 383 | { 384 | this.textBox1.AppendText("1.初次使用正确输入路径名称及范围,并初始化任务\n\n"); 385 | 386 | this.textBox1.AppendText("2.第一次初始化某个任务时三个标记位不需要修改\n\n"); 387 | 388 | this.textBox1.AppendText("3.初始化完毕后,开始下载数据\n\n"); 389 | 390 | this.textBox1.AppendText("4.下载完毕后,由于下载数目太多,下载过程中很容易出错,此时调整标记位,把需要下载的标记位的值设置为之前下载错误的标记位的值,同时给下载错误的标记位设置新值\n\n"); 391 | 392 | this.textBox1.AppendText("5.继续点击开始下载,把之前下载错误的瓦片数据重新下载一次\n\n"); 393 | 394 | this.textBox1.AppendText("6.如下载过程中关机或者关闭程序,再次打开程序后,只需选择之前的路径并输入和之前一样的任务名称后点击开始下载即可\n\n"); 395 | } 396 | } 397 | } 398 | -------------------------------------------------------------------------------- /GMapDownLoad/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 107, 17 125 | 126 | -------------------------------------------------------------------------------- /GMapDownLoad/GMapDownLoad.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {DABC98CA-8F4B-404F-AFB5-8DE392E7B87E} 8 | WinExe 9 | Properties 10 | GoogleMapDownLoad 11 | GoogleMapDownLoad 12 | v4.5 13 | 512 14 | 3c46ad16 15 | 16 | 17 | 18 | AnyCPU 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | false 27 | 28 | 29 | AnyCPU 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | false 37 | 38 | 39 | 40 | ..\packages\cyqdata.5.7.8.2\lib\net\CYQ.Data.dll 41 | True 42 | 43 | 44 | ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll 45 | True 46 | 47 | 48 | 49 | 50 | ..\packages\System.Data.SQLite.Core.1.0.107.0\lib\net45\System.Data.SQLite.dll 51 | True 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | Form 66 | 67 | 68 | Form1.cs 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Form1.cs 77 | 78 | 79 | ResXFileCodeGenerator 80 | Resources.Designer.cs 81 | Designer 82 | 83 | 84 | True 85 | Resources.resx 86 | True 87 | 88 | 89 | Always 90 | 91 | 92 | 93 | SettingsSingleFileGenerator 94 | Settings.Designer.cs 95 | 96 | 97 | True 98 | Settings.settings 99 | True 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 110 | 111 | 112 | 113 | 120 | -------------------------------------------------------------------------------- /GMapDownLoad/HttpHelper.cs: -------------------------------------------------------------------------------- 1 | /// 2 | /// 类说明:HttpHelper类,用来实现Http访问,Post或者Get方式的,直接访问,带Cookie的,带证书的等方式,可以设置代理 3 | /// 重要提示:请不要自行修改本类,如果因为你自己修改后将无法升级到新版本。如果确实有什么问题请到官方网站提建议, 4 | /// 我们一定会及时修改 5 | /// 编码日期:2011-09-20 6 | /// 编 码 人:苏飞 7 | /// 联系方式:361983679 8 | /// 官方网址:http://www.sufeinet.com/thread-3-1-1.html 9 | /// 修改日期:2017-01-16 10 | /// 版 本 号:1.8 11 | /// 12 | using System; 13 | using System.Collections.Generic; 14 | using System.Text; 15 | using System.Net; 16 | using System.IO; 17 | using System.Text.RegularExpressions; 18 | using System.IO.Compression; 19 | using System.Security.Cryptography.X509Certificates; 20 | using System.Net.Security; 21 | 22 | namespace DotNet.Utilities 23 | { 24 | /// 25 | /// Http连接操作帮助类 26 | /// 27 | public class HttpHelper 28 | { 29 | 30 | #region 预定义方变量 31 | //默认的编码 32 | private Encoding encoding = Encoding.Default; 33 | //Post数据编码 34 | private Encoding postencoding = Encoding.Default; 35 | //HttpWebRequest对象用来发起请求 36 | private HttpWebRequest request = null; 37 | //获取影响流的数据对象 38 | private HttpWebResponse response = null; 39 | //设置本地的出口ip和端口 40 | private IPEndPoint _IPEndPoint = null; 41 | #endregion 42 | 43 | #region Public 44 | 45 | /// 46 | /// 根据相传入的数据,得到相应页面数据 47 | /// 48 | /// 参数类对象 49 | /// 返回HttpResult类型 50 | public HttpResult GetHtml(HttpItem item) 51 | { 52 | //返回参数 53 | HttpResult result = new HttpResult(); 54 | try 55 | { 56 | //准备参数 57 | SetRequest(item); 58 | } 59 | catch (Exception ex) 60 | { 61 | result.Cookie = string.Empty; 62 | result.Header = null; 63 | result.Html = ex.Message; 64 | result.StatusDescription = "配置参数时出错:" + ex.Message; 65 | //配置参数时出错 66 | return result; 67 | } 68 | try 69 | { 70 | //请求数据 71 | using (response = (HttpWebResponse)request.GetResponse()) 72 | { 73 | GetData(item, result); 74 | } 75 | } 76 | catch (WebException ex) 77 | { 78 | if (ex.Response != null) 79 | { 80 | using (response = (HttpWebResponse)ex.Response) 81 | { 82 | GetData(item, result); 83 | } 84 | } 85 | else 86 | { 87 | result.Html = ex.Message; 88 | } 89 | } 90 | catch (Exception ex) 91 | { 92 | result.Html = ex.Message; 93 | } 94 | if (item.IsToLower) result.Html = result.Html.ToLower(); 95 | return result; 96 | } 97 | #endregion 98 | 99 | #region GetData 100 | 101 | /// 102 | /// 获取数据的并解析的方法 103 | /// 104 | /// 105 | /// 106 | private void GetData(HttpItem item, HttpResult result) 107 | { 108 | #region base 109 | //获取StatusCode 110 | result.StatusCode = response.StatusCode; 111 | //获取StatusDescription 112 | result.StatusDescription = response.StatusDescription; 113 | //获取最后访问的URl 114 | result.ResponseUri = response.ResponseUri.ToString(); 115 | //获取Headers 116 | result.Header = response.Headers; 117 | //获取CookieCollection 118 | if (response.Cookies != null) result.CookieCollection = response.Cookies; 119 | //获取set-cookie 120 | if (response.Headers["set-cookie"] != null) result.Cookie = response.Headers["set-cookie"]; 121 | #endregion 122 | 123 | #region byte 124 | //处理网页Byte 125 | byte[] ResponseByte = GetByte(); 126 | #endregion 127 | 128 | #region Html 129 | if (ResponseByte != null && ResponseByte.Length > 0) 130 | { 131 | //设置编码 132 | SetEncoding(item, result, ResponseByte); 133 | //得到返回的HTML 134 | result.Html = encoding.GetString(ResponseByte); 135 | } 136 | else 137 | { 138 | //没有返回任何Html代码 139 | result.Html = string.Empty; 140 | } 141 | #endregion 142 | } 143 | /// 144 | /// 设置编码 145 | /// 146 | /// HttpItem 147 | /// HttpResult 148 | /// byte[] 149 | private void SetEncoding(HttpItem item, HttpResult result, byte[] ResponseByte) 150 | { 151 | //是否返回Byte类型数据 152 | if (item.ResultType == ResultType.Byte) result.ResultByte = ResponseByte; 153 | //从这里开始我们要无视编码了 154 | if (encoding == null) 155 | { 156 | Match meta = Regex.Match(Encoding.Default.GetString(ResponseByte), " 0) 159 | { 160 | c = meta.Groups[1].Value.ToLower().Trim(); 161 | } 162 | if (c.Length > 2) 163 | { 164 | try 165 | { 166 | encoding = Encoding.GetEncoding(c.Replace("\"", string.Empty).Replace("'", "").Replace(";", "").Replace("iso-8859-1", "gbk").Trim()); 167 | } 168 | catch 169 | { 170 | if (string.IsNullOrEmpty(response.CharacterSet)) 171 | { 172 | encoding = Encoding.UTF8; 173 | } 174 | else 175 | { 176 | encoding = Encoding.GetEncoding(response.CharacterSet); 177 | } 178 | } 179 | } 180 | else 181 | { 182 | if (string.IsNullOrEmpty(response.CharacterSet)) 183 | { 184 | encoding = Encoding.UTF8; 185 | } 186 | else 187 | { 188 | encoding = Encoding.GetEncoding(response.CharacterSet); 189 | } 190 | } 191 | } 192 | } 193 | /// 194 | /// 提取网页Byte 195 | /// 196 | /// 197 | private byte[] GetByte() 198 | { 199 | byte[] ResponseByte = null; 200 | MemoryStream _stream = new MemoryStream(); 201 | 202 | //GZIIP处理 203 | if (response.ContentEncoding != null && response.ContentEncoding.Equals("gzip", StringComparison.InvariantCultureIgnoreCase)) 204 | { 205 | //开始读取流并设置编码方式 206 | _stream = GetMemoryStream(new GZipStream(response.GetResponseStream(), CompressionMode.Decompress)); 207 | } 208 | else 209 | { 210 | //开始读取流并设置编码方式 211 | _stream = GetMemoryStream(response.GetResponseStream()); 212 | } 213 | //获取Byte 214 | ResponseByte = _stream.ToArray(); 215 | _stream.Close(); 216 | return ResponseByte; 217 | } 218 | 219 | /// 220 | /// 4.0以下.net版本取数据使用 221 | /// 222 | /// 流 223 | private MemoryStream GetMemoryStream(Stream streamResponse) 224 | { 225 | MemoryStream _stream = new MemoryStream(); 226 | int Length = 256; 227 | Byte[] buffer = new Byte[Length]; 228 | int bytesRead = streamResponse.Read(buffer, 0, Length); 229 | while (bytesRead > 0) 230 | { 231 | _stream.Write(buffer, 0, bytesRead); 232 | bytesRead = streamResponse.Read(buffer, 0, Length); 233 | } 234 | return _stream; 235 | } 236 | #endregion 237 | 238 | #region SetRequest 239 | 240 | /// 241 | /// 为请求准备参数 242 | /// 243 | ///参数列表 244 | private void SetRequest(HttpItem item) 245 | { 246 | // 验证证书 247 | SetCer(item); 248 | if (item.IPEndPoint != null) 249 | { 250 | _IPEndPoint = item.IPEndPoint; 251 | //设置本地的出口ip和端口 252 | request.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIPEndPointCallback); 253 | } 254 | //设置Header参数 255 | if (item.Header != null && item.Header.Count > 0) foreach (string key in item.Header.AllKeys) 256 | { 257 | request.Headers.Add(key, item.Header[key]); 258 | } 259 | // 设置代理 260 | SetProxy(item); 261 | if (item.ProtocolVersion != null) request.ProtocolVersion = item.ProtocolVersion; 262 | request.ServicePoint.Expect100Continue = item.Expect100Continue; 263 | //请求方式Get或者Post 264 | request.Method = item.Method; 265 | request.Timeout = item.Timeout; 266 | request.KeepAlive = item.KeepAlive; 267 | request.ReadWriteTimeout = item.ReadWriteTimeout; 268 | if (item.IfModifiedSince != null) request.IfModifiedSince = Convert.ToDateTime(item.IfModifiedSince); 269 | //Accept 270 | request.Accept = item.Accept; 271 | //ContentType返回类型 272 | request.ContentType = item.ContentType; 273 | //UserAgent客户端的访问类型,包括浏览器版本和操作系统信息 274 | request.UserAgent = item.UserAgent; 275 | // 编码 276 | encoding = item.Encoding; 277 | //设置安全凭证 278 | request.Credentials = item.ICredentials; 279 | //设置Cookie 280 | SetCookie(item); 281 | //来源地址 282 | request.Referer = item.Referer; 283 | //是否执行跳转功能 284 | request.AllowAutoRedirect = item.Allowautoredirect; 285 | if (item.MaximumAutomaticRedirections > 0) 286 | { 287 | request.MaximumAutomaticRedirections = item.MaximumAutomaticRedirections; 288 | } 289 | //设置Post数据 290 | SetPostData(item); 291 | //设置最大连接 292 | if (item.Connectionlimit > 0) request.ServicePoint.ConnectionLimit = item.Connectionlimit; 293 | } 294 | /// 295 | /// 设置证书 296 | /// 297 | /// 298 | private void SetCer(HttpItem item) 299 | { 300 | if (!string.IsNullOrEmpty(item.CerPath)) 301 | { 302 | //这一句一定要写在创建连接的前面。使用回调的方法进行证书验证。 303 | ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult); 304 | //初始化对像,并设置请求的URL地址 305 | request = (HttpWebRequest)WebRequest.Create(item.URL); 306 | SetCerList(item); 307 | //将证书添加到请求里 308 | request.ClientCertificates.Add(new X509Certificate(item.CerPath)); 309 | } 310 | else 311 | { 312 | //初始化对像,并设置请求的URL地址 313 | request = (HttpWebRequest)WebRequest.Create(item.URL); 314 | SetCerList(item); 315 | } 316 | } 317 | /// 318 | /// 设置多个证书 319 | /// 320 | /// 321 | private void SetCerList(HttpItem item) 322 | { 323 | if (item.ClentCertificates != null && item.ClentCertificates.Count > 0) 324 | { 325 | foreach (X509Certificate c in item.ClentCertificates) 326 | { 327 | request.ClientCertificates.Add(c); 328 | } 329 | } 330 | } 331 | /// 332 | /// 设置Cookie 333 | /// 334 | /// Http参数 335 | private void SetCookie(HttpItem item) 336 | { 337 | if (!string.IsNullOrEmpty(item.Cookie)) request.Headers[HttpRequestHeader.Cookie] = item.Cookie; 338 | //设置CookieCollection 339 | if (item.ResultCookieType == ResultCookieType.CookieCollection) 340 | { 341 | request.CookieContainer = new CookieContainer(); 342 | if (item.CookieCollection != null && item.CookieCollection.Count > 0) 343 | request.CookieContainer.Add(item.CookieCollection); 344 | } 345 | } 346 | /// 347 | /// 设置Post数据 348 | /// 349 | /// Http参数 350 | private void SetPostData(HttpItem item) 351 | { 352 | //验证在得到结果时是否有传入数据 353 | if (!request.Method.Trim().ToLower().Contains("get")) 354 | { 355 | if (item.PostEncoding != null) 356 | { 357 | postencoding = item.PostEncoding; 358 | } 359 | byte[] buffer = null; 360 | //写入Byte类型 361 | if (item.PostDataType == PostDataType.Byte && item.PostdataByte != null && item.PostdataByte.Length > 0) 362 | { 363 | //验证在得到结果时是否有传入数据 364 | buffer = item.PostdataByte; 365 | }//写入文件 366 | else if (item.PostDataType == PostDataType.FilePath && !string.IsNullOrEmpty(item.Postdata)) 367 | { 368 | StreamReader r = new StreamReader(item.Postdata, postencoding); 369 | buffer = postencoding.GetBytes(r.ReadToEnd()); 370 | r.Close(); 371 | } //写入字符串 372 | else if (!string.IsNullOrEmpty(item.Postdata)) 373 | { 374 | buffer = postencoding.GetBytes(item.Postdata); 375 | } 376 | if (buffer != null) 377 | { 378 | request.ContentLength = buffer.Length; 379 | request.GetRequestStream().Write(buffer, 0, buffer.Length); 380 | } 381 | else 382 | { 383 | request.ContentLength = 0; 384 | } 385 | } 386 | } 387 | /// 388 | /// 设置代理 389 | /// 390 | /// 参数对象 391 | private void SetProxy(HttpItem item) 392 | { 393 | bool isIeProxy = false; 394 | if (!string.IsNullOrEmpty(item.ProxyIp)) 395 | { 396 | isIeProxy = item.ProxyIp.ToLower().Contains("ieproxy"); 397 | } 398 | if (!string.IsNullOrEmpty(item.ProxyIp) && !isIeProxy) 399 | { 400 | //设置代理服务器 401 | if (item.ProxyIp.Contains(":")) 402 | { 403 | string[] plist = item.ProxyIp.Split(':'); 404 | WebProxy myProxy = new WebProxy(plist[0].Trim(), Convert.ToInt32(plist[1].Trim())); 405 | //建议连接 406 | myProxy.Credentials = new NetworkCredential(item.ProxyUserName, item.ProxyPwd); 407 | //给当前请求对象 408 | request.Proxy = myProxy; 409 | } 410 | else 411 | { 412 | WebProxy myProxy = new WebProxy(item.ProxyIp, false); 413 | //建议连接 414 | myProxy.Credentials = new NetworkCredential(item.ProxyUserName, item.ProxyPwd); 415 | //给当前请求对象 416 | request.Proxy = myProxy; 417 | } 418 | } 419 | else if (isIeProxy) 420 | { 421 | //设置为IE代理 422 | } 423 | else 424 | { 425 | request.Proxy = item.WebProxy; 426 | } 427 | } 428 | #endregion 429 | 430 | #region private main 431 | /// 432 | /// 回调验证证书问题 433 | /// 434 | /// 流对象 435 | /// 证书 436 | /// X509Chain 437 | /// SslPolicyErrors 438 | /// bool 439 | private bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; } 440 | 441 | /// 442 | /// 通过设置这个属性,可以在发出连接的时候绑定客户端发出连接所使用的IP地址。 443 | /// 444 | /// 445 | /// 446 | /// 447 | /// 448 | private IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) 449 | { 450 | return _IPEndPoint;//端口号 451 | } 452 | #endregion 453 | } 454 | /// 455 | /// Http请求参考类 456 | /// 457 | public class HttpItem 458 | { 459 | string _URL = string.Empty; 460 | /// 461 | /// 请求URL必须填写 462 | /// 463 | public string URL 464 | { 465 | get { return _URL; } 466 | set { _URL = value; } 467 | } 468 | string _Method = "GET"; 469 | /// 470 | /// 请求方式默认为GET方式,当为POST方式时必须设置Postdata的值 471 | /// 472 | public string Method 473 | { 474 | get { return _Method; } 475 | set { _Method = value; } 476 | } 477 | int _Timeout = 100000; 478 | /// 479 | /// 默认请求超时时间 480 | /// 481 | public int Timeout 482 | { 483 | get { return _Timeout; } 484 | set { _Timeout = value; } 485 | } 486 | int _ReadWriteTimeout = 30000; 487 | /// 488 | /// 默认写入Post数据超时间 489 | /// 490 | public int ReadWriteTimeout 491 | { 492 | get { return _ReadWriteTimeout; } 493 | set { _ReadWriteTimeout = value; } 494 | } 495 | Boolean _KeepAlive = true; 496 | /// 497 | /// 获取或设置一个值,该值指示是否与 Internet 资源建立持久性连接默认为true。 498 | /// 499 | public Boolean KeepAlive 500 | { 501 | get { return _KeepAlive; } 502 | set { _KeepAlive = value; } 503 | } 504 | string _Accept = "text/html, application/xhtml+xml, */*"; 505 | /// 506 | /// 请求标头值 默认为text/html, application/xhtml+xml, */* 507 | /// 508 | public string Accept 509 | { 510 | get { return _Accept; } 511 | set { _Accept = value; } 512 | } 513 | string _ContentType = "text/html"; 514 | /// 515 | /// 请求返回类型默认 text/html 516 | /// 517 | public string ContentType 518 | { 519 | get { return _ContentType; } 520 | set { _ContentType = value; } 521 | } 522 | string _UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; 523 | /// 524 | /// 客户端访问信息默认Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) 525 | /// 526 | public string UserAgent 527 | { 528 | get { return _UserAgent; } 529 | set { _UserAgent = value; } 530 | } 531 | Encoding _Encoding = null; 532 | /// 533 | /// 返回数据编码默认为NUll,可以自动识别,一般为utf-8,gbk,gb2312 534 | /// 535 | public Encoding Encoding 536 | { 537 | get { return _Encoding; } 538 | set { _Encoding = value; } 539 | } 540 | private PostDataType _PostDataType = PostDataType.String; 541 | /// 542 | /// Post的数据类型 543 | /// 544 | public PostDataType PostDataType 545 | { 546 | get { return _PostDataType; } 547 | set { _PostDataType = value; } 548 | } 549 | string _Postdata = string.Empty; 550 | /// 551 | /// Post请求时要发送的字符串Post数据 552 | /// 553 | public string Postdata 554 | { 555 | get { return _Postdata; } 556 | set { _Postdata = value; } 557 | } 558 | private byte[] _PostdataByte = null; 559 | /// 560 | /// Post请求时要发送的Byte类型的Post数据 561 | /// 562 | public byte[] PostdataByte 563 | { 564 | get { return _PostdataByte; } 565 | set { _PostdataByte = value; } 566 | } 567 | private WebProxy _WebProxy; 568 | /// 569 | /// 设置代理对象,不想使用IE默认配置就设置为Null,而且不要设置ProxyIp 570 | /// 571 | public WebProxy WebProxy 572 | { 573 | get { return _WebProxy; } 574 | set { _WebProxy = value; } 575 | } 576 | 577 | CookieCollection cookiecollection = null; 578 | /// 579 | /// Cookie对象集合 580 | /// 581 | public CookieCollection CookieCollection 582 | { 583 | get { return cookiecollection; } 584 | set { cookiecollection = value; } 585 | } 586 | string _Cookie = string.Empty; 587 | /// 588 | /// 请求时的Cookie 589 | /// 590 | public string Cookie 591 | { 592 | get { return _Cookie; } 593 | set { _Cookie = value; } 594 | } 595 | string _Referer = string.Empty; 596 | /// 597 | /// 来源地址,上次访问地址 598 | /// 599 | public string Referer 600 | { 601 | get { return _Referer; } 602 | set { _Referer = value; } 603 | } 604 | string _CerPath = string.Empty; 605 | /// 606 | /// 证书绝对路径 607 | /// 608 | public string CerPath 609 | { 610 | get { return _CerPath; } 611 | set { _CerPath = value; } 612 | } 613 | private Boolean isToLower = false; 614 | /// 615 | /// 是否设置为全文小写,默认为不转化 616 | /// 617 | public Boolean IsToLower 618 | { 619 | get { return isToLower; } 620 | set { isToLower = value; } 621 | } 622 | private Boolean allowautoredirect = false; 623 | /// 624 | /// 支持跳转页面,查询结果将是跳转后的页面,默认是不跳转 625 | /// 626 | public Boolean Allowautoredirect 627 | { 628 | get { return allowautoredirect; } 629 | set { allowautoredirect = value; } 630 | } 631 | private int connectionlimit = 1024; 632 | /// 633 | /// 最大连接数 634 | /// 635 | public int Connectionlimit 636 | { 637 | get { return connectionlimit; } 638 | set { connectionlimit = value; } 639 | } 640 | private string proxyusername = string.Empty; 641 | /// 642 | /// 代理Proxy 服务器用户名 643 | /// 644 | public string ProxyUserName 645 | { 646 | get { return proxyusername; } 647 | set { proxyusername = value; } 648 | } 649 | private string proxypwd = string.Empty; 650 | /// 651 | /// 代理 服务器密码 652 | /// 653 | public string ProxyPwd 654 | { 655 | get { return proxypwd; } 656 | set { proxypwd = value; } 657 | } 658 | private string proxyip = string.Empty; 659 | /// 660 | /// 代理 服务IP ,如果要使用IE代理就设置为ieproxy 661 | /// 662 | public string ProxyIp 663 | { 664 | get { return proxyip; } 665 | set { proxyip = value; } 666 | } 667 | private ResultType resulttype = ResultType.String; 668 | /// 669 | /// 设置返回类型String和Byte 670 | /// 671 | public ResultType ResultType 672 | { 673 | get { return resulttype; } 674 | set { resulttype = value; } 675 | } 676 | private WebHeaderCollection header = new WebHeaderCollection(); 677 | /// 678 | /// header对象 679 | /// 680 | public WebHeaderCollection Header 681 | { 682 | get { return header; } 683 | set { header = value; } 684 | } 685 | 686 | private Version _ProtocolVersion; 687 | 688 | /// 689 | // 获取或设置用于请求的 HTTP 版本。返回结果:用于请求的 HTTP 版本。默认为 System.Net.HttpVersion.Version11。 690 | /// 691 | public Version ProtocolVersion 692 | { 693 | get { return _ProtocolVersion; } 694 | set { _ProtocolVersion = value; } 695 | } 696 | private Boolean _expect100continue = false; 697 | /// 698 | /// 获取或设置一个 System.Boolean 值,该值确定是否使用 100-Continue 行为。如果 POST 请求需要 100-Continue 响应,则为 true;否则为 false。默认值为 true。 699 | /// 700 | public Boolean Expect100Continue 701 | { 702 | get { return _expect100continue; } 703 | set { _expect100continue = value; } 704 | } 705 | private X509CertificateCollection _ClentCertificates; 706 | /// 707 | /// 设置509证书集合 708 | /// 709 | public X509CertificateCollection ClentCertificates 710 | { 711 | get { return _ClentCertificates; } 712 | set { _ClentCertificates = value; } 713 | } 714 | private Encoding _PostEncoding; 715 | /// 716 | /// 设置或获取Post参数编码,默认的为Default编码 717 | /// 718 | public Encoding PostEncoding 719 | { 720 | get { return _PostEncoding; } 721 | set { _PostEncoding = value; } 722 | } 723 | private ResultCookieType _ResultCookieType = ResultCookieType.String; 724 | /// 725 | /// Cookie返回类型,默认的是只返回字符串类型 726 | /// 727 | public ResultCookieType ResultCookieType 728 | { 729 | get { return _ResultCookieType; } 730 | set { _ResultCookieType = value; } 731 | } 732 | 733 | private ICredentials _ICredentials = CredentialCache.DefaultCredentials; 734 | /// 735 | /// 获取或设置请求的身份验证信息。 736 | /// 737 | public ICredentials ICredentials 738 | { 739 | get { return _ICredentials; } 740 | set { _ICredentials = value; } 741 | } 742 | /// 743 | /// 设置请求将跟随的重定向的最大数目 744 | /// 745 | private int _MaximumAutomaticRedirections; 746 | 747 | public int MaximumAutomaticRedirections 748 | { 749 | get { return _MaximumAutomaticRedirections; } 750 | set { _MaximumAutomaticRedirections = value; } 751 | } 752 | 753 | private DateTime? _IfModifiedSince = null; 754 | /// 755 | /// 获取和设置IfModifiedSince,默认为当前日期和时间 756 | /// 757 | public DateTime? IfModifiedSince 758 | { 759 | get { return _IfModifiedSince; } 760 | set { _IfModifiedSince = value; } 761 | } 762 | #region ip-port 763 | private IPEndPoint _IPEndPoint = null; 764 | /// 765 | /// 设置本地的出口ip和端口 766 | /// ] 767 | /// 768 | ///item.IPEndPoint = new IPEndPoint(IPAddress.Parse("192.168.1.1"),80); 769 | /// 770 | public IPEndPoint IPEndPoint 771 | { 772 | get { return _IPEndPoint; } 773 | set { _IPEndPoint = value; } 774 | } 775 | #endregion 776 | } 777 | /// 778 | /// Http返回参数类 779 | /// 780 | public class HttpResult 781 | { 782 | private string _Cookie; 783 | /// 784 | /// Http请求返回的Cookie 785 | /// 786 | public string Cookie 787 | { 788 | get { return _Cookie; } 789 | set { _Cookie = value; } 790 | } 791 | 792 | private CookieCollection _CookieCollection; 793 | /// 794 | /// Cookie对象集合 795 | /// 796 | public CookieCollection CookieCollection 797 | { 798 | get { return _CookieCollection; } 799 | set { _CookieCollection = value; } 800 | } 801 | private string _html = string.Empty; 802 | /// 803 | /// 返回的String类型数据 只有ResultType.String时才返回数据,其它情况为空 804 | /// 805 | public string Html 806 | { 807 | get { return _html; } 808 | set { _html = value; } 809 | } 810 | private byte[] _ResultByte; 811 | /// 812 | /// 返回的Byte数组 只有ResultType.Byte时才返回数据,其它情况为空 813 | /// 814 | public byte[] ResultByte 815 | { 816 | get { return _ResultByte; } 817 | set { _ResultByte = value; } 818 | } 819 | private WebHeaderCollection _Header; 820 | /// 821 | /// header对象 822 | /// 823 | public WebHeaderCollection Header 824 | { 825 | get { return _Header; } 826 | set { _Header = value; } 827 | } 828 | private string _StatusDescription; 829 | /// 830 | /// 返回状态说明 831 | /// 832 | public string StatusDescription 833 | { 834 | get { return _StatusDescription; } 835 | set { _StatusDescription = value; } 836 | } 837 | private HttpStatusCode _StatusCode; 838 | /// 839 | /// 返回状态码,默认为OK 840 | /// 841 | public HttpStatusCode StatusCode 842 | { 843 | get { return _StatusCode; } 844 | set { _StatusCode = value; } 845 | } 846 | /// 847 | /// 最后访问的URl 848 | /// 849 | public string ResponseUri { get; set; } 850 | /// 851 | /// 获取重定向的URl 852 | /// 853 | public string RedirectUrl 854 | { 855 | get 856 | { 857 | try 858 | { 859 | if (Header != null && Header.Count > 0) 860 | { 861 | string baseurl = Header["location"].ToString().Trim(); 862 | string locationurl = baseurl.ToLower(); 863 | if (!string.IsNullOrWhiteSpace(locationurl)) 864 | { 865 | bool b = locationurl.StartsWith("http://") || locationurl.StartsWith("https://"); 866 | if (!b) 867 | { 868 | baseurl = new Uri(new Uri(ResponseUri), baseurl).AbsoluteUri; 869 | } 870 | } 871 | return baseurl; 872 | } 873 | } 874 | catch { } 875 | return string.Empty; 876 | } 877 | 878 | } 879 | } 880 | /// 881 | /// 返回类型 882 | /// 883 | public enum ResultType 884 | { 885 | /// 886 | /// 表示只返回字符串 只有Html有数据 887 | /// 888 | String, 889 | /// 890 | /// 表示返回字符串和字节流 ResultByte和Html都有数据返回 891 | /// 892 | Byte 893 | } 894 | /// 895 | /// Post的数据格式默认为string 896 | /// 897 | public enum PostDataType 898 | { 899 | /// 900 | /// 字符串类型,这时编码Encoding可不设置 901 | /// 902 | String, 903 | /// 904 | /// Byte类型,需要设置PostdataByte参数的值编码Encoding可设置为空 905 | /// 906 | Byte, 907 | /// 908 | /// 传文件,Postdata必须设置为文件的绝对路径,必须设置Encoding的值 909 | /// 910 | FilePath 911 | } 912 | /// 913 | /// Cookie返回类型 914 | /// 915 | public enum ResultCookieType 916 | { 917 | /// 918 | /// 只返回字符串类型的Cookie 919 | /// 920 | String, 921 | /// 922 | /// CookieCollection格式的Cookie集合同时也返回String类型的cookie 923 | /// 924 | CookieCollection 925 | } 926 | } -------------------------------------------------------------------------------- /GMapDownLoad/Log4Net.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /GMapDownLoad/LogHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | public class LogHelper 8 | { 9 | public static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("log4net"); 10 | 11 | public static void WriteLog(string info) 12 | { 13 | 14 | if (loginfo.IsInfoEnabled) 15 | { 16 | loginfo.Info(info); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /GMapDownLoad/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace WindowsFormsApplication1 7 | { 8 | static class Program 9 | { 10 | /// 11 | /// 应用程序的主入口点。 12 | /// 13 | [STAThread] 14 | static void Main() 15 | { 16 | Application.EnableVisualStyles(); 17 | Application.SetCompatibleTextRenderingDefault(false); 18 | Application.Run(new Form1()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /GMapDownLoad/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("GoogleMapDownLoad")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("GoogleMapDownLoad")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("f91ae33b-59ac-49ac-b32b-f1cd25ebeb1d")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: log4net.Config.DOMConfigurator(ConfigFile = "Log4Net.config", Watch = true)] 38 | -------------------------------------------------------------------------------- /GMapDownLoad/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace GoogleMapDownLoad.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GoogleMapDownLoad.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 使用此强类型资源类,为所有资源查找 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /GMapDownLoad/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /GMapDownLoad/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace GoogleMapDownLoad.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /GMapDownLoad/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GMapDownLoad/TitleClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace WindowsFormsApplication1 8 | { 9 | class TitleClass 10 | { 11 | /// 12 | /// 13 | /// 14 | /// 经度 15 | /// 纬度 16 | /// 17 | /// 18 | public static PointF WorldToTilePos(double lon, double lat, int zoom) 19 | { 20 | PointF p = new Point(); 21 | p.X = (float)((lon + 180.0) / 360.0 * (1 << zoom)); 22 | p.Y = (float)((1.0 - Math.Log(Math.Tan(lat * Math.PI / 180.0) + 23 | 1.0 / Math.Cos(lat * Math.PI / 180.0)) / Math.PI) / 2.0 * (1 << zoom)); 24 | 25 | return p; 26 | } 27 | 28 | public static Point WorldToTilePosP(double lon, double lat, int zoom) 29 | { 30 | Point p = new Point(); 31 | p.X = (int)Math.Floor((lon + 180.0) / 360.0 * (1 << zoom)); 32 | p.Y = (int)Math.Floor((1.0 - Math.Log(Math.Tan(lat * Math.PI / 180.0) + 33 | 1.0 / Math.Cos(lat * Math.PI / 180.0)) / Math.PI) / 2.0 * (1 << zoom)); 34 | 35 | return p; 36 | } 37 | 38 | public static PointF TileToWorldPos(double tile_x, double tile_y, int zoom) 39 | { 40 | PointF p = new Point(); 41 | double n = Math.PI - ((2.0 * Math.PI * tile_y) / Math.Pow(2.0, zoom)); 42 | 43 | p.X = (float)((tile_x / Math.Pow(2.0, zoom) * 360.0) - 180.0); 44 | p.Y = (float)(180.0 / Math.PI * Math.Atan(Math.Sinh(n))); 45 | 46 | return p; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /GMapDownLoad/dt.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanggangbz/MapDownLoad/5248ca9bcbb4be12a6effda0a105aecf8c5247cb/GMapDownLoad/dt.db -------------------------------------------------------------------------------- /GMapDownLoad/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MapDownLoad 2 | 谷歌地图瓦片数据下载工具 3 | 4 | * 由于一些原因,需要下载一个地图的瓦片数据,网上有很多地图下载工具,但是功能都比较复杂强大,下载地图数据时如果范围过大,经常会在下载途中出现各种问题,要么内存爆了,要么崩溃了 5 | 6 | * 找工具确实花费了不少的时间,最后还不如自己写一个,功能极其简单,只是单独下载瓦片数据而已(只实现了谷歌卫星地图瓦片数据下载,为了能和dem高程数据对上,下的是无偏移的数据) 7 | 8 | * 通过经纬度信息计算tile索引的方法参考自: 9 | * [Slippy map tilenames](https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames) 10 | * [Google tile和TMS的索引算法](https://www.cnblogs.com/Tangf/archive/2012/04/07/2435545.html) 11 | 12 | * 瓦片数据体量灰常大,下载之前自己计算准备好足够的磁盘空间,同时也得考虑大量文件个数到时候删除会很头疼的 13 | 14 | * 谷歌地图最大19级,部分区域18级 15 | 16 | ## 工具使用并行来循环下载瓦片数据,没有延时机制,大量下载数据有被谷歌封IP的风险 17 | --------------------------------------------------------------------------------