forked from judero01col/GMap.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
467 lines (364 loc) · 14.9 KB
/
Program.cs
1
2
3
4
5
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using DotSpatial.Projections;
using GMap.NET;
using GMap.NET.Internals;
using GMap.NET.MapProviders;
using GMap.NET.Projections;
namespace ConsoleApplication
{
class test
{
//const int batchSize = 3;
const int logSize = 8; //1024 * 8;
readonly PointLatLng[] gpsLog = new PointLatLng[logSize];
int logCounter;
bool logFull;
public IEnumerable<PointLatLng> GpsLogView()
{
int i = 0;
var last = PointLatLng.Empty;
foreach (var l in GpsLog())
{
if (i++ <= 4)
{
last = l;
yield return l;
}
else
{
if (MercatorProjection.Instance.GetDistance(l, last) > 0.1)
{
last = l;
yield return l;
}
}
}
}
public IEnumerable<PointLatLng> GpsLog()
{
for (int i = logCounter - 1; i >= 0; i--)
{
yield return gpsLog[i];
}
if (logFull)
{
for (int i = logSize - 1, start = logCounter; i >= start; i--)
{
yield return gpsLog[i];
}
}
}
public void AddToLogCurrentInfo(PointLatLng data)
{
gpsLog[logCounter++] = data;
if (logCounter == logSize)
{
logCounter = 0;
logFull = true;
}
}
public void Go()
{
for (int i = 0; i < 160; i++)
{
AddToLogCurrentInfo(new PointLatLng(i, 0));
Debug.WriteLine("i: " + i);
foreach (var l in GpsLog())
{
Debug.Write(l.Lat + " ");
}
Debug.WriteLine("");
Debug.WriteLine("-----------");
}
}
}
class Program
{
static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
Debug.WriteLine("LoadedAssembly.FullName: " + args.LoadedAssembly.FullName);
}
static void Main(string[] args)
{
//var t = new test();
//t.Go();
//return;
try
{
int c = 0;
int type = GMapProviders.LithuaniaTOP50Map.DbId;
//GMaps.Instance.PrimaryCache.DeleteOlderThan(DateTime.MaxValue, type);
var import = Directory.GetFiles(@"T:\tiles\Layer_NewLayer\", "*.jpg", SearchOption.AllDirectories)
.Where(p => p.Contains("Layer_") && !p.Contains("black")).ToList();
int total = import.Count;
foreach (string i in import)
{
//using (Bitmap pic = new Bitmap(i))
//{
// for (int ii = 0; ii < pic.Width; ii++)
// {
// for (int j = 0; j < pic.Height; j++)
// {
// if (pic.GetPixel(ii, j) == Color.Black)
// {
// }
// }
// }
//}
string qk = Path.GetFileNameWithoutExtension(i);
int x = 0;
int y = 0;
int z = 0;
GMapProviders.BingMap.QuadKeyToTileXY(qk, out x, out y, out z);
Debug.WriteLine(c++ + " of " + total + ", x: " + x + ", y: " + y + ", z: " + z);
if (!GMaps.Instance.PrimaryCache.PutImageToCache(File.ReadAllBytes(i), type, new GPoint(x, y), z))
{
break;
}
}
}
catch (Exception ex)
{
Debug.WriteLine("import: " + ex);
}
if (false)
{
var dirs = Directory.GetDirectories(@"D:\Temp\tmap\TOP50LKS");
foreach (string dir in dirs)
{
var jpg = Directory.GetFiles(dir, "*.jpg");
string files = Path.GetFileName(dir).Replace(" ", string.Empty) + " ";
if (File.Exists(@"D:\Temp\tmap\tmp\" + files.Replace(" ", string.Empty) + ".png"))
{
Debug.WriteLine("SKIP: " + dir);
continue;
}
foreach (string j in jpg)
{
files += "\"" + j + "\" ";
}
string ice = @"D:\Projektai\Test\ice\ice2\ICE\bin\x64\Debug\ICE.exe";
//string ice = @"C:\Program Files\Microsoft Research\Image Composite Editor\ICE.exe";
Debug.WriteLine("process: " + dir);
Process.Start(ice, files).WaitForExit();
//break;
}
}
return;
AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad;
GMapProvider.WebProxy = new WebProxy("127.0.0.1", 1080);
GMapProvider.IsSocksProxy = true;
//GMapProvider.WebProxy = WebRequest.DefaultWebProxy;
//Debug.WriteLine("DbId: " + GMapProviders.YahooMap.DbId);
if (false)
{
GMaps.Instance.EnableTileHost(8844);
Console.ReadLine();
GMaps.Instance.DisableTileHost();
GMaps.Instance.CancelTileCaching();
return;
}
if (false)
{
GeoCoderStatusCode status;
var pp1 = GMapProviders.GoogleMap.GetPoint("Lithuania, Seda", out status);
return;
}
if (false)
{
GeoCoderStatusCode status;
var pp1 = GMapProviders.GoogleMap.GetPoint("Lithuania, vilnius, Antakalnio g. 67-35", out status);
List<Placemark> plc = null;
//var st = GMapProviders.GoogleMap.GetPlacemarks(new PointLatLng(54.6961334816182, 25.2985095977782), out plc);
var st = GMapProviders.GoogleMap.GetPlacemarks(pp1.Value, out plc);
if (st == GeoCoderStatusCode.OK && plc != null)
{
foreach (var pl in plc)
{
if (!string.IsNullOrEmpty(pl.PostalCodeNumber))
{
Debug.WriteLine("Accuracy: " + pl.Accuracy + ", " + pl.Address + ", PostalCodeNumber: " +
pl.PostalCodeNumber);
}
}
}
return;
}
if (false)
{
var p1 = new PointLatLng(54.6961334816182, 25.2985095977782);
var p2 = new PointLatLng(54.7061334816182, 25.3085095977783);
//GMaps.Instance.ImportFromGMDB(@"C:\Users\m.dambrauskas\AppData\Local\GMap.NET\TileDBv5\en\Data - Copy.gmdb");
//var route = GMapProviders.OpenStreetMap.GetRoute(p1, p2, false, false, 10);
//var route = GMapProviders.CloudMadeMap.GetRoute(p1, p2, false, false, 10);
//Debug.WriteLine(GMapProviders.BingHybridMap.Name + ":" + GMapProviders.BingHybridMap.DbId);
GeoCoderStatusCode status;
var pp1 = GMapProviders.GoogleMap.GetPoint("Lithuania,Vilnius", out status);
var pp2 = GMapProviders.GoogleMap.GetPoint("Lithuania,Kaunas", out status);
if (pp1.HasValue && pp2.HasValue)
{
GDirections s;
//var x = GMapProviders.GoogleMap.GetDirections(out s, "Lithuania,Vilnius", "Lithuania,Kaunas", false, false, false, true);
//if(x == DirectionsStatusCode.OK)
var x = GMapProviders.GoogleMap.GetDirections(out s,
pp1.Value,
pp2.Value,
false,
false,
false,
false,
true);
{
Debug.WriteLine(s.Summary + ", " + s.Copyrights);
Debug.WriteLine(s.StartAddress + " -> " + s.EndAddress);
Debug.WriteLine(s.Distance);
Debug.WriteLine(s.Duration);
foreach (var step in s.Steps)
{
Debug.WriteLine(step);
}
}
}
}
if (false)
{
var p = PlateCarreeProjectionDarbAe.Instance;
var l = new PointLatLng(29.4052130085331, 41.522866508209);
Debug.WriteLine("121 * 256: " + 121 * 256 + "px : Y");
Debug.WriteLine("144 * 256: " + 144 * 256 + "px : X");
Debug.WriteLine("l: " + l);
var px = p.FromLatLngToPixel(l, 0);
Debug.WriteLine("FromLatLngToPixel: " + px);
var ll = p.FromPixelToLatLng(px, 0);
Debug.WriteLine("FromPixelToLatLng: " + ll);
var tl = p.FromPixelToTileXY(px);
Debug.WriteLine("FromPixelToTileXY: " + tl);
}
/*
0/1 = 2
1/2 = 1,5
2/3 = 2
3/4 = 2
4/5 = 2,5
5/6 = 2
6/7 = 2
7/8 = 2
8/9 = 2,5
9/10 = 2
10/11 = 2,5
11/12 = 2
*/
if (false)
{
var p = LKS94Projection.Instance;
//var p = PlateCarreeProjection.Instance;
var pos = new PointLatLng(54.6961334816182, 25.2985095977783);
{
int zoom = 4;
var px = p.FromPixelToTileXY(p.FromLatLngToPixel(pos, zoom));
Exception ex = null;
var img = GMaps.Instance.GetImageFrom(GMapProviders.LithuaniaMap, px, zoom, out ex);
File.WriteAllBytes(zoom + "z-" + px + ".png", img.Data.ToArray());
}
for (int i = 0; i < 12; i++)
{
double scale = p.GetGroundResolution(i, pos.Lat);
double scale2 = p.GetGroundResolution(i + 1, pos.Lat);
double s = scale / scale2;
Debug.WriteLine(i + "/" + (i + 1) + " = " + s);
}
}
#if DEBUG
if (false)
{
//GMaps.Instance.PrimaryCache.DeleteOlderThan(DateTime.Now, GMapProviders.GoogleMap.DbId);
GMaps.Instance.Mode = AccessMode.CacheOnly;
using (var c = new Core())
{
//c.compensationOffset = new GPoint(200, 200);
c.MinZoom = 1;
c.MaxZoom = 25;
c.Zoom = 16;
c.Provider = GMapProviders.OpenStreetMap;
c.Position = new PointLatLng(54.6961334816182, 25.2985095977783);
c.OnMapSizeChanged(400, 400);
c.OnMapOpen();
Debug.WriteLine("Position: " + c.Position);
Debug.WriteLine("renderOffset: " + c.RenderOffset);
Debug.WriteLine("compensationOffset: " + c.CompensationOffset);
var l = c.FromLatLngToLocal(c.Position);
Debug.WriteLine("local: " + l);
var g = c.FromLocalToLatLng(l.X, l.Y);
Debug.WriteLine("geo: " + g);
//c.ReloadMap();
Console.ReadLine();
c.OnMapClose();
}
}
if (false)
{
int i = 0;
//while(true)
{
Console.WriteLine(i + " start");
Debug.WriteLine(i + " start");
//using(Core c = new Core())
var c = new Core();
{
var f = c.OnMapOpen();
Console.WriteLine("wait");
Console.ReadLine();
//c.OnMapClose();
}
c = null;
Debug.WriteLine("end");
Console.WriteLine("end");
Console.ReadLine();
GC.Collect();
//if(i++ > 10)
//{
// GC.Collect();
// i = 0;
//}
}
}
#endif
if (false)
{
//-34,8859309407532, Lng=-58,359375
var p1 = new PointLatLng(-34.608, -58.348);
var p2 = new PointLatLng(-34.608, -58.348);
//Sets up a array to contain the x and y coordinates
var xy = new double[4] {p1.Lng, p1.Lat, p2.Lng, p2.Lat};
//An array for the z coordinate
var z = new double[1];
z[0] = 1;
var pStart = KnownCoordinateSystems.Geographic.World.WGS1984;
var pEnd = new ProjectionInfo();
//ProjectionInfo pEnd = new ProjectionInfo("+proj=tmerc +lat_0=0 +lon_0=15 +k=0.9996 +x_0=4200000 +y_0=-1300000 +ellps=WGS84 +datum=WGS84 +to_meter=0.03125 +no_defs");
//ProjectionInfo pEnd = new ProjectionInfo("+proj=tmerc +lat_0=-34.629269 +lon_0=-58.4633 +k=0.9999980000000001 +x_0=100000 +y_0=100000 +ellps=intl +units=m +no_defs");
Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 2);
Debug.WriteLine(" true1: " + (int)xy[0] + "; " + (int)xy[1]);
//var prj = new MapyCZProjection();
//{
// var p2 = prj.WGSToPP(y, x);
// Debug.WriteLine("false1: " + p2[0] + "; " + p2[1]);
// var p3 = prj.PPToWGS(p2[0], p2[1]);
// Reproject.ReprojectPoints(xy, z, pEnd, pStart, 0, 1);
// Debug.WriteLine("");
// Debug.WriteLine(" true2: " + xy[0] + "; " + xy[1]);
// Debug.WriteLine("false2: " + p3[1] + "; " + p3[0]);
//}
// 134400000],PARAMETER["false_northing",-41600000
}
// stop caching immediately
GMaps.Instance.CancelTileCaching();
//Console.ReadLine();
}
}
}