-
Notifications
You must be signed in to change notification settings - Fork 4
/
DemController.cs
2299 lines (1985 loc) · 88.4 KB
/
DemController.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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using blct;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System.Threading;
using System.Text;
namespace PDERLTest.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class DemController : ControllerBase
{
public DemController(DemAnalysisService _demService)
{
demAnalysisService = _demService;
}
readonly DemAnalysisService demAnalysisService;
#region 基础服务
/// <summary>
/// 列举当前有哪些DEM文件
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult<object> Get()
{
return
new
{
Current = System.IO.Path.GetFileNameWithoutExtension(demAnalysisService.FilePath),
AllFiles = from p in System.IO.Directory.GetFiles("../../DEM/", "*.tif", SearchOption.TopDirectoryOnly)
select System.IO.Path.GetFileNameWithoutExtension(p)
};
}
/// <summary>
/// 设置当前要计算的DEM
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[HttpGet("setdem/{path}")]
public ActionResult<bool> SetDem(string path)
{
demAnalysisService.FilePath = "../../DEM/" + path + ".tif";
return true;
}
/// <summary>
/// PDERL算法求通视区域(直接调用的默认方法)
/// </summary>
/// <param name="lon"></param>
/// <param name="lat"></param>
/// <param name="toLon"></param>
/// <param name="toLat"></param>
/// <param name="dh">距离地面相对高度</param>
/// <returns></returns>
[HttpGet("analysis/{lon}/{lat}/{toLon}/{toLat}/{dh}")]
public ActionResult<object> GetAnalysisDefaultByPderl(double lon, double lat, double toLon, double toLat, double dh)
{
var date = DateTime.Now;
demAnalysisService.Analysis.DoAnalysisByPedrlLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_PDERL, out double demMinX, out double demMinY, out double perX, out double perY);
var PDERLTime = DateTime.Now - date;
//获取通视率
double VisibleRate = GetVisibleRate(result_PDERL);
//可见区域绘制的线
//var VisibleLines = GetDrawLines(result_PDERL, perX, perY, demMinX, demMinY);
float dlon = (float)perX * result_PDERL.GetLength(0);
float dlat = (float)perY * result_PDERL.GetLength(1);
float startLon = (float)(lon - dlon / 2);
float startLat = (float)(lat - dlat / 2);
var VisiblePoints = new
{
hierarchy = new float[] {
startLon,startLat,
startLon+dlon,startLat,
startLon+dlon,startLat+dlat,
startLon,startLat+dlat,
startLon,startLat,
},
values = result_PDERL,
x = result_PDERL.GetLength(0),
y = result_PDERL.GetLength(1)
};
return new
{
VisiblePoints,
Time = PDERLTime,
AllCount = result_PDERL.GetLength(0) * result_PDERL.GetLength(1),
};
}
[HttpGet("analysis_pderl/{lon}/{lat}/{toLon}/{toLat}/{dh}")]
public ActionResult<object> GetAnalysisDefault_Pderl(double lon, double lat, double toLon, double toLat, double dh)
{
var date = DateTime.Now;
demAnalysisService.Analysis.DoAnalysisByPedrlLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_PDERL, out double demMinX, out double demMinY, out double perX, out double perY);
var PDERLTime = DateTime.Now - date;
//获取通视率
double VisibleRate = GetVisibleRate(result_PDERL);
//可见区域绘制的线
//var VisibleLines = GetDrawLines(result_PDERL, perX, perY, demMinX, demMinY);
float dlon = (float)perX * result_PDERL.GetLength(0);
float dlat = (float)perY * result_PDERL.GetLength(1);
float startLon = (float)(lon - dlon / 2);
float startLat = (float)(lat - dlat / 2);
var VisiblePoints = new
{
hierarchy = new float[] {
startLon,startLat,
startLon+dlon,startLat,
startLon+dlon,startLat+dlat,
startLon,startLat+dlat,
startLon,startLat,
},
values = result_PDERL,
x = result_PDERL.GetLength(0),
y = result_PDERL.GetLength(1)
};
return new
{
VisiblePoints,
Time = PDERLTime,
AllCount = result_PDERL.GetLength(0) * result_PDERL.GetLength(1),
};
}
[HttpGet("analysis_xpderl/{lon}/{lat}/{toLon}/{toLat}/{dh}")]
public ActionResult<object> GetAnalysisDefault_xPderl(double lon, double lat, double toLon, double toLat, double dh)
{
var date = DateTime.Now;
demAnalysisService.Analysis.DoAnalysisByXPderlLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_PDERL, out double demMinX, out double demMinY, out double perX, out double perY);
var PDERLTime = DateTime.Now - date;
//获取通视率
double VisibleRate = GetVisibleRate(result_PDERL);
//可见区域绘制的线
//var VisibleLines = GetDrawLines(result_PDERL, perX, perY, demMinX, demMinY);
float dlon = (float)perX * result_PDERL.GetLength(0);
float dlat = (float)perY * result_PDERL.GetLength(1);
float startLon = (float)(lon - dlon / 2);
float startLat = (float)(lat - dlat / 2);
var VisiblePoints = new
{
hierarchy = new float[] {
startLon,startLat,
startLon+dlon,startLat,
startLon+dlon,startLat+dlat,
startLon,startLat+dlat,
startLon,startLat,
},
values = result_PDERL,
x = result_PDERL.GetLength(0),
y = result_PDERL.GetLength(1)
};
return new
{
VisiblePoints,
Time = PDERLTime,
AllCount = result_PDERL.GetLength(0) * result_PDERL.GetLength(1),
};
}
#endregion
#region PDERL自动测试
[HttpGet("analysis_auto_test")]
public ActionResult<string> DoAnalysis_AutoTest()
{
new Thread(new ParameterizedThreadStart((ob) =>
{
SetDem("Copernicus_DSM_COG_10_N41_00_E119_00_DEM");
for (double i = 0; i < 100; i++)
{
DoAnalysisGetNeighborErrWithR3(0.00925, 2, 500, "Copernicus_DSM_COG_10_N41_00_E119_00_DEM");
}
})).Start();
return "开始测试";
}
/// <summary>
/// 批量测试精度(与R3对比)
/// </summary>
[HttpGet("analysis_auto_test_accuracy")]
public ActionResult<string> DoAnalysis_AutoTest_Accuracy()
{
new Thread(new ParameterizedThreadStart((ob) =>
{
Random r = new Random();
double step = 0;
SetDem("Copernicus_DSM_COG_10_N41_00_E119_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(119.1, 41.3 + step, 119.9, 41.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(119.1, 41.3 + step, 119.9, 41.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(119.1, 41.3 + step, 119.9, 41.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(119.1, 41.3 + step, 119.9, 41.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(119.1, 41.3 + step, 119.9, 41.1 + step, 1, 10);
SetDem("Copernicus_DSM_COG_10_N34_00_E114_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(114.1, 34.3 + step, 114.9, 34.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(114.1, 34.3 + step, 114.9, 34.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(114.1, 34.3 + step, 114.9, 34.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(114.1, 34.3 + step, 114.9, 34.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(114.1, 34.3 + step, 114.9, 34.1 + step, 1, 10);
SetDem("Copernicus_DSM_COG_10_N28_00_E097_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(097.1, 28.3 + step, 097.9, 28.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(097.1, 28.3 + step, 097.9, 28.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(097.1, 28.3 + step, 097.9, 28.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(097.1, 28.3 + step, 097.9, 28.1 + step, 1, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(097.1, 28.3 + step, 097.9, 28.1 + step, 1, 10);
for (double h = 25; h < 5001; h += 25)
{
SetDem("Copernicus_DSM_COG_10_N41_00_E119_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(119.1, 41.3 + step, 119.9, 41.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(119.1, 41.3 + step, 119.9, 41.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(119.1, 41.3 + step, 119.9, 41.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(119.1, 41.3 + step, 119.9, 41.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(119.1, 41.3 + step, 119.9, 41.1 + step, h, 10);
SetDem("Copernicus_DSM_COG_10_N34_00_E114_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(114.1, 34.3 + step, 114.9, 34.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(114.1, 34.3 + step, 114.9, 34.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(114.1, 34.3 + step, 114.9, 34.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(114.1, 34.3 + step, 114.9, 34.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(114.1, 34.3 + step, 114.9, 34.1 + step, h, 10);
SetDem("Copernicus_DSM_COG_10_N28_00_E097_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(097.1, 28.3 + step, 097.9, 28.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(097.1, 28.3 + step, 097.9, 28.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(097.1, 28.3 + step, 097.9, 28.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(097.1, 28.3 + step, 097.9, 28.1 + step, h, 10);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe(097.1, 28.3 + step, 097.9, 28.1 + step, h, 10);
}
})).Start();
return "开始测试";
}
/// <summary>
/// 自动测试邻域错误(一个进程只能有一个测试)
/// </summary>
[HttpGet("analysis_auto_test_neighbor_err")]
public ActionResult<string> DoAnalysis_AutoTest_NeighborErr(int p = 0)
{
new Thread(new ParameterizedThreadStart((ob) =>
{
string demFile = "";
if (p == 1)
demFile = ("Copernicus_DSM_COG_10_N41_00_E119_00_DEM");
else if (p == 2)
demFile = ("Copernicus_DSM_COG_10_N34_00_E114_00_DEM");
else if (p == 3)
demFile = ("Copernicus_DSM_COG_10_N28_00_E097_00_DEM");
else
return;
SetDem(demFile);
for (double h = 2; h < 54; h += 2)
{
DoAnalysisGetNeighborErrWithR3(0.051, h, 500, demFile);
}
})).Start();
return "开始测试";
}
/// <summary>
/// 自动测试PDERL、XDraw、参考面算法在不同高度的速度对比
/// </summary>
[HttpGet("analysis_auto_test_time_without_r3")]
public ActionResult<string> DoAnalysis_AutoTest_TimeWithoutR3()
{
new Thread(new ParameterizedThreadStart((ob) =>
{
double h = 5000;
//for (double h = 1; h < 5000; h += 1)
{
SetDem("Copernicus_DSM_COG_10_N41_00_E119_00_DEM");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, h, 1);
SetDem("Copernicus_DSM_COG_10_N34_00_E114_00_DEM");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, h, 1);
SetDem("Copernicus_DSM_COG_10_N28_00_E097_00_DEM");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, h, 1);
}
})).Start();
return "开始测试";
}
#endregion
#region XPDERL自动测试
/// <summary>
/// 3.1 Experiment 1: speed
/// 自动测试PDERL、XDraw、参考面算法在不同高度的速度对比
/// </summary>
[HttpGet("x_analysis_auto_test_time_without_r3")]
public ActionResult<string> X_DoAnalysis_AutoTest_TimeWithoutR3()
{
new Thread(new ParameterizedThreadStart((ob) =>
{
SetDem("Copernicus_DSM_COG_10_N41_00_E119_00_DEM");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, 1, 100);
SetDem("Copernicus_DSM_COG_10_N34_00_E114_00_DEM");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, 1, 100);
SetDem("Copernicus_DSM_COG_10_N28_00_E097_00_DEM");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, 1, 100);
for (double h = 10; h <= 5000; h+=10)
{
SetDem("Copernicus_DSM_COG_10_N41_00_E119_00_DEM");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, h, 100);
SetDem("Copernicus_DSM_COG_10_N34_00_E114_00_DEM");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, h, 100);
SetDem("Copernicus_DSM_COG_10_N28_00_E097_00_DEM");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, h, 100);
}
})).Start();
return "开始测试,由于测试量巨大,可能需要等待8小时以上,请关注报告的数据量大小,直到不再增长为止";
}
/// <summary>
/// 3.1 Experiment 2: accuracy
/// 批量测试精度(与PDERL对比)
/// </summary>
[HttpGet("x_analysis_auto_test_accuracy")]
public ActionResult<string> X_DoAnalysis_AutoTest_Accuracy()
{
new Thread(new ParameterizedThreadStart((ob) =>
{
Random r = new Random();
double step = 0;//用于随机范围
SetDem("Copernicus_DSM_COG_10_N41_00_E119_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(119.1, 41.3 + step, 119.9, 41.1 + step, 1, 100);//在指定范围内随机半径进行测试
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(119.1, 41.3 + step, 119.9, 41.1 + step, 1, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(119.1, 41.3 + step, 119.9, 41.1 + step, 1, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(119.1, 41.3 + step, 119.9, 41.1 + step, 1, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(119.1, 41.3 + step, 119.9, 41.1 + step, 1, 100);
SetDem("Copernicus_DSM_COG_10_N34_00_E114_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(114.1, 34.3 + step, 114.9, 34.1 + step, 1, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(114.1, 34.3 + step, 114.9, 34.1 + step, 1, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(114.1, 34.3 + step, 114.9, 34.1 + step, 1, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(114.1, 34.3 + step, 114.9, 34.1 + step, 1, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(114.1, 34.3 + step, 114.9, 34.1 + step, 1, 100);
SetDem("Copernicus_DSM_COG_10_N28_00_E097_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(097.1, 28.3 + step, 097.9, 28.1 + step, 1, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(097.1, 28.3 + step, 097.9, 28.1 + step, 1, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(097.1, 28.3 + step, 097.9, 28.1 + step, 1, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(097.1, 28.3 + step, 097.9, 28.1 + step, 1, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(097.1, 28.3 + step, 097.9, 28.1 + step, 1, 100);
for (double h = 50; h < 5001; h += 50)
{
SetDem("Copernicus_DSM_COG_10_N41_00_E119_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(119.1, 41.3 + step, 119.9, 41.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(119.1, 41.3 + step, 119.9, 41.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(119.1, 41.3 + step, 119.9, 41.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(119.1, 41.3 + step, 119.9, 41.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(119.1, 41.3 + step, 119.9, 41.1 + step, h, 100);
SetDem("Copernicus_DSM_COG_10_N34_00_E114_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(114.1, 34.3 + step, 114.9, 34.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(114.1, 34.3 + step, 114.9, 34.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(114.1, 34.3 + step, 114.9, 34.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(114.1, 34.3 + step, 114.9, 34.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(114.1, 34.3 + step, 114.9, 34.1 + step, h, 100);
SetDem("Copernicus_DSM_COG_10_N28_00_E097_00_DEM");
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(097.1, 28.3 + step, 097.9, 28.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(097.1, 28.3 + step, 097.9, 28.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(097.1, 28.3 + step, 097.9, 28.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(097.1, 28.3 + step, 097.9, 28.1 + step, h, 100);
step = r.NextDouble() * 0.6;
DoAnalysisAllPrecRe_PDERL(097.1, 28.3 + step, 097.9, 28.1 + step, h, 100);
}
})).Start();
return "开始测试,由于测试量巨大,可能需要等待8小时以上,请关注报告的数据量大小,直到不再增长为止";
}
/// <summary>
/// 3.3 Experiment 3: aggregation of error points
/// 自动测试邻域错误(一个进程只能有一个测试)
/// </summary>
[HttpGet("x_analysis_auto_test_neighbor_err")]
public ActionResult<string> X_DoAnalysis_AutoTest_NeighborErr(int p = 0)
{
new Thread(new ParameterizedThreadStart((ob) =>
{
string demFile = "";
if (p == 1)
demFile = ("Copernicus_DSM_COG_10_N41_00_E119_00_DEM");
else if (p == 2)
demFile = ("Copernicus_DSM_COG_10_N34_00_E114_00_DEM");
else if (p == 3)
demFile = ("Copernicus_DSM_COG_10_N28_00_E097_00_DEM");
else
return;
SetDem(demFile);
for (double h = 3; h < 76; h += 3)
{
//Console.WriteLine(demFile);
DoAnalysisGetNeighborErrWithPDERL(0.1, h, 1000, demFile);
}
//进行半径和聚集程度测试
for (double r = 0.01; r < 0.11; r += 0.01)
{
DoAnalysisGetNeighborErrWithPDERL(r, 3, 1000, demFile + "[半径聚集程度测试]");
}
})).Start();
return "开始测试,由于测试量巨大,可能需要等待8小时以上,请关注报告的数据量大小,直到不再增长为止";
}
/// <summary>
/// get the histogram of each dem
/// copy the result to excel to get a histogram
/// </summary>
/// <returns></returns>
[HttpGet("histogram")]
public ActionResult<object> GetHistogramValues()
{
var AllFiles = from p in System.IO.Directory.GetFiles("../../DEM/", "*.tif", SearchOption.TopDirectoryOnly)
select p;
StringBuilder report = new StringBuilder();
report.Append("图号\t最低\t最高\t");
List<string> id = new List<string>();
Dictionary<string, int> dic = new Dictionary<string, int>();
for (int i = 0; i < 10000; i += 100)//对于地形10000米已经足够高了
{
string si = i + "-" + (i + 100);
dic[si] = 0;
id.Add(si);
report.Append(si);
report.Append("\t");
}
report.Append("\n");
foreach (var filePath in AllFiles)
{
DEM dem = new DEM(filePath, 30);
double min = dem.Height[0, 0];
double max = dem.Height[0, 0];
report.Append(System.IO.Path.GetFileNameWithoutExtension(filePath) + "\t");
for (int i = 0; i < dem.XSize; i++)
for (int j = 0; j < dem.YSize; j++)
{
dic[id[((int)(dem.Height[i, j] / 100))]]++;
if(dem.Height[i, j] > max)
{
max = dem.Height[i, j];
}
if(dem.Height[i, j] < min)
{
min = dem.Height[i, j];
}
}
report.Append(min + "\t" + max + "\t");
foreach (string i in id)
{
report.Append(dic[i] + "\t");
dic[i] = 0;
}
report.Append("\n");
}
return report.ToString();
}
/// <summary>
/// FAB对比
/// </summary>
/// <returns></returns>
[HttpGet("x_analysis_auto_test_time_without_r3_fab_test")]
public ActionResult<string> X_DoAnalysis_AutoTest_TimeWithoutR3_Fab()
{
new Thread(new ParameterizedThreadStart((ob) =>
{
SetDem("Copernicus_DSM_COG_10_N34_00_E113_00_DEM");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, 1, 100);
SetDem("N34E113_FABDEM_V1-0");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, 1, 100);
for (double h = 10; h <= 5000; h += 10)
{
SetDem("Copernicus_DSM_COG_10_N34_00_E113_00_DEM");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, h, 100);
SetDem("N34E113_FABDEM_V1-0");
DoAnalysisTimeRodomRepeateWithoutR3(0.1, h, 100);
}
})).Start();
return "开始测试";
}
/// <summary>
/// FAB对比
/// 批量测试精度(与PDERL对比)
/// </summary>
[HttpGet("x_analysis_auto_test_accuracy_fab_test")]
public ActionResult<string> X_DoAnalysis_AutoTest_Accuracy_FAB()
{
new Thread(new ParameterizedThreadStart((ob) =>
{
Random r = new Random();
SetDem("Copernicus_DSM_COG_10_N34_00_E113_00_DEM");
DoAnalysisAllPrecRe_PDERL(113.526111, 34.878333333, 113.81194444, 34.66916667, 1, 500);//在指定范围内随机半径进行测试
SetDem("N34E113_FABDEM_V1-0");
DoAnalysisAllPrecRe_PDERL(113.526111, 34.878333333, 113.81194444, 34.66916667, 1, 500);//在指定范围内随机半径进行测试
for (double h = 50; h < 5001; h += 50)
{
SetDem("Copernicus_DSM_COG_10_N34_00_E113_00_DEM");
DoAnalysisAllPrecRe_PDERL(113.526111, 34.878333333, 113.81194444, 34.66916667, h, 500);//在指定范围内随机半径进行测试
SetDem("N34E113_FABDEM_V1-0");
DoAnalysisAllPrecRe_PDERL(113.526111, 34.878333333, 113.81194444, 34.66916667, h, 500);//在指定范围内随机半径进行测试
}
})).Start();
return "开始测试";
}
#endregion
#region 各种算法与R3的单独精度比较
[HttpGet("analysis_osd/{lon}/{lat}/{toLon}/{toLat}/{dh}")]
public ActionResult<object> DoAnalysisPDERL(double lon, double lat, double toLon, double toLat, double dh)
{
//return DoAnalysis(demAnalysisService.Analysis.DoAnalysisByOsdLL_Refer, lon, lat, toLon, toLat, dh);
return DoAnalysis(demAnalysisService.Analysis.DoAnalysisByPedrlLonLat, lon, lat, toLon, toLat, dh);
}
[HttpGet("analysis_fast_osd/{lon}/{lat}/{toLon}/{toLat}/{dh}")]
public ActionResult<object> DoAnalysisXPDERL(double lon, double lat, double toLon, double toLat, double dh)
{
return DoAnalysis(demAnalysisService.Analysis.DoAnalysisByXPderlLonLat, lon, lat, toLon, toLat, dh);
}
[HttpGet("analysis_xdraw/{lon}/{lat}/{toLon}/{toLat}/{dh}")]
public ActionResult<object> DoAnalysisXDraw(double lon, double lat, double toLon, double toLat, double dh)
{
return DoAnalysis(demAnalysisService.Analysis.DoAnalysisByXDrawLonLat, lon, lat, toLon, toLat, dh);
}
[HttpGet("analysis_reff/{lon}/{lat}/{toLon}/{toLat}/{dh}")]
public ActionResult<object> DoAnalysisRp(double lon, double lat, double toLon, double toLat, double dh)
{
return DoAnalysis(demAnalysisService.Analysis.DoAnalysisByRpLonLat, lon, lat, toLon, toLat, dh);
}
/// <summary>
/// 指定方法与R3的对比
/// </summary>
/// <param name="DoAnalysisLL">指定的算法</param>
/// <param name="lon"></param>
/// <param name="lat"></param>
/// <param name="toLon"></param>
/// <param name="toLat"></param>
/// <param name="dh"></param>
/// <returns>
/// {
/// VisibleLines,//可见区域绘制的线
/// Time,//计算时间
/// R3Time,//R3耗时
/// AllPointCount,//共计算了多少点量
/// VisibleRate,//计算区域的通视率
/// VisibleErrPoints,//将本来可见的判错
/// UnVisibleErrPoints,//将本来不可见的判错
/// VisibleErrCount,//可见点判错数量
/// UnVisibleErrCount,//不可见点判错数量
/// VisibleErrRate,//可见点错误率
/// UnVisibleErrRate,//不可见点错误率
/// ErrRate//整体错误率
/// }
/// </returns>
private object DoAnalysis(DemAnalysisHandle.DoAnalysisLonLat DoAnalysisLL, double lon, double lat, double toLon, double toLat, double dh)
{
var date = DateTime.Now;
//PDERL算法
DoAnalysisLL(lon, lat, toLon, toLat, dh,
out int[,] result, out double demMinX, out double demMinY, out double perX, out double perY);
var Time = DateTime.Now - date;
date = DateTime.Now;
//R3算法
demAnalysisService.Analysis.DoAnalysisByR3LonLat(lon, lat, toLon, toLat, dh,
out int[,] result_R3, out double utmLeftLon4, out double utmBottomLat4, out double perX4, out double perY4);
var R3Time = DateTime.Now - date;
date = DateTime.Now;
int lonCount = result_R3.GetLength(0);
double halfLon = lonCount / 2.0;
int latCount = result_R3.GetLength(1);
double halfLat = latCount / 2.0;
int AllPointCount = lonCount * latCount;
//获取通视率
double VisibleRate = GetVisibleRate(result_R3);
//错点数量
int VisibleErrCount = 0;
int UnVisibleErrCount = 0;
List<object> VisibleErrPoints = new List<object>();
List<object> UnVisibleErrPoints = new List<object>();
for (int i = 0; i < lonCount; i++)
for (int j = 0; j < latCount; j++)
{
if (result_R3[i, j] == 1 && result[i, j] == 0)//本来能看见的判为看不见
{
VisibleErrPoints.Add(new { i, j });
VisibleErrCount++;
}
else if (result_R3[i, j] == 0 && result[i, j] == 1)//本来看不见的判为能看见
{
UnVisibleErrPoints.Add(new { i, j });
UnVisibleErrCount++;
}
}
//错点率
double ErrRate = (double)(UnVisibleErrCount + VisibleErrCount) / AllPointCount;
double VisibleErrRate = (double)(VisibleErrCount) / AllPointCount;
double UnVisibleErrRate = (double)(UnVisibleErrCount) / AllPointCount;
float dlon = (float)perX * result.GetLength(0);
float dlat = (float)perY * result.GetLength(1);
float startLon = (float)(lon - dlon / 2);
float startLat = (float)(lat - dlat / 2);
//可见区
var VisiblePoints = new
{
hierarchy = new float[] {
startLon,startLat,
startLon+dlon,startLat,
startLon+dlon,startLat+dlat,
startLon,startLat+dlat,
startLon,startLat,
},
values = result,
x = result.GetLength(0),
y = result.GetLength(1)
};
return new
{
Time,//计算时间
R3Time,//R3计算时间
AllPointCount,//共计算了多少点量
VisibleRate,//计算区域的通视率
VisibleErrPoints,//将本来可见的判错
UnVisibleErrPoints,//将本来不可见的判错
VisibleErrCount,//可见点判错数量
UnVisibleErrCount,//不可见点判错数量
VisibleErrRate,//可见点错误率
UnVisibleErrRate,//不可见点错误率
ErrRate,//整体错误率
VisiblePoints,//可见区域绘制的线
};
}
#endregion
#region 实时测试,这几个方法不会记录日志,主要是给前端实时测试准备的
/// <summary>
/// 通过在当前DEM文件的最大范围进行计算,来比较PDERL、XPDERL、XDraw、参考面算法的速度
/// </summary>
/// <returns>
/// {
/// AllCount,//总点数
/// PDERLTime,//PDERL方法时间
/// XPDERLTime,//快速PDERL方法时间
/// RefTime,//参考面方法时间
/// XDrawTime,//XDraw方法时间
/// }
/// </returns>
[HttpGet("CompareMax")]
public ActionResult<object> GetCompareByLargeAmountPoints()
{
var date = DateTime.Now;
double lon = 119.51, lat = 41.5123, toLon = 119.95, toLat = 41.5, dh = 2;
demAnalysisService.Analysis.DoAnalysisByPedrlLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_PDERL, out double demMinX, out double demMinY, out double perX, out double perY);
var PDERLTime = DateTime.Now - date;
date = DateTime.Now;
demAnalysisService.Analysis.DoAnalysisByXPderlLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_XPDERL, out double utmLeftLon2, out double utmBottomLat2, out double perX2, out double perY2);
var XPDERLTime = DateTime.Now - date;
date = DateTime.Now;
demAnalysisService.Analysis.DoAnalysisByRpLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_RefF, out double utmLeftLon5, out double utmBottomLat5, out double perX5, out double perY5);
var RefTime = DateTime.Now - date;
date = DateTime.Now;
demAnalysisService.Analysis.DoAnalysisByXDrawLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_XDraw, out double utmLeftLon3, out double utmBottomLat3, out double perX3, out double perY3);
var XDrawTime = DateTime.Now - date;
date = DateTime.Now;
return new
{
AllCount = (int)(result_PDERL.GetLength(0) * result_PDERL.GetLength(1)),
PDERLTime,
XPDERLTime,
RefTime,
XDrawTime
};
}
/// <summary>
/// 对比各种算法的耗时、错误点数、错误率等(以R3为对比)
/// </summary>
/// <param name="lon"></param>
/// <param name="lat"></param>
/// <param name="toLon"></param>
/// <param name="toLat"></param>
/// <param name="dh"></param>
/// <returns>
/// </returns>
[HttpGet("analysis_all/{lon}/{lat}/{toLon}/{toLat}/{dh}")]
public ActionResult<object> GetAnalysisAll(double lon, double lat,
double toLon, double toLat, double dh)
{
var date = DateTime.Now;
#region 计算
//PDERL算法
demAnalysisService.Analysis.DoAnalysisByPedrlLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_PDERL, out double demMinX, out double demMinY, out double perX, out double perY);
var PDERLTime = DateTime.Now - date;
date = DateTime.Now;
//XPDERL算法
demAnalysisService.Analysis.DoAnalysisByXPderlLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_XPDERL, out double utmLeftLon2, out double utmBottomLat2, out double perX2, out double perY2);
var XPDERLTime = DateTime.Now - date;
date = DateTime.Now;
//参考面算法
demAnalysisService.Analysis.DoAnalysisByRpLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_RefF, out double utmLeftLon5, out double utmBottomLat5, out double perX5, out double perY5);
var RefTime = DateTime.Now - date;
date = DateTime.Now;
//XDraw算法
demAnalysisService.Analysis.DoAnalysisByXDrawLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_XDraw, out double utmLeftLon3, out double utmBottomLat3, out double perX3, out double perY3);
var XDrawTime = DateTime.Now - date;
date = DateTime.Now;
//R3算法
demAnalysisService.Analysis.DoAnalysisByR3LonLat(lon, lat, toLon, toLat, dh,
out int[,] result_R3, out double utmLeftLon4, out double utmBottomLat4, out double perX4, out double perY4);
var R3Time = DateTime.Now - date;
#endregion
#region 获取通视率、比较错点数量及错误比率
//获取通视率
double VisibleRate = GetVisibleRate(result_R3);
int lonCount = result_PDERL.GetLength(0);
double halfLon = lonCount / 2.0;
int latCount = result_PDERL.GetLength(1);
double halfLat = latCount / 2.0;
int AllPointCount = lonCount * latCount;
GetErrRate(result_PDERL, result_R3, lonCount, latCount, AllPointCount, out int PDERLErrPointCount, out double PDERLErrRate);
GetErrRate(result_XPDERL, result_R3, lonCount, latCount, AllPointCount, out int XPDERLErrPointCount, out double XPDERLErrRate);
GetErrRate(result_XDraw, result_R3, lonCount, latCount, AllPointCount, out int XDrawErrPointCount, out double XDrawErrRate);
GetErrRate(result_RefF, result_R3, lonCount, latCount, AllPointCount, out int RefFErrPointCount, out double RefFErrRate);
#endregion
return new
{
//计算总点数:代表计算量
AllPointCount,
//通视率
VisibleRate,
//耗时
R3Time,
PDERLTime,
XPDERLTime,
XDrawTime,
RefTime,
//错误点数
PDERLErrPointCount,
XPDERLErrPointCount,
XDrawErrPointCount,
RefFErrPointCount,
//错误率
PDERLErrRate,
XPDERLErrRate,
XDrawErrRate,
RefFErrRate
};
}
/// <summary>
/// 计算各种算法同时进行等半径范围比较(精度参照R3)
/// </summary>
/// <param name="DoAnalysisLL"></param>
/// <param name="lon"></param>
/// <param name="lat"></param>
/// <param name="r"></param>
/// <param name="dh"></param>
/// <param name="max">最多计算多少个点,大于0有效</param>
/// <returns></returns>
[HttpGet("analysis_all_fixed_r/{r}/{dh}/{max}")]
public object DoAnalysisRodomRepeateAll(double r, double dh, int max)
{
Random radom = new Random();
List<object> items = new List<object>();
double dlon = demAnalysisService.DemData.DX;
double dlat = demAnalysisService.DemData.DY;
var startLon = demAnalysisService.DemData.StartX + r + dlon + 0.00181;//避免正好在格网上
var startLat = demAnalysisService.DemData.StartY + r + dlat + 0.00181;
var maxLon = demAnalysisService.DemData.MaxLon - r - dlon - 0.00181;
var maxLat = demAnalysisService.DemData.MaxY - r - dlat - 0.00181;
double count = 0;
for (double lon = startLon; lon < maxLon; lon += dlon)
{
for (double lat = startLat; lat < maxLat; lat += dlat)
{
if (max > 0 && count > max)
break;
else
count++;
var toLon = lon + r;
var toLat = lat;
var date = DateTime.Now;
//PDERL算法
demAnalysisService.Analysis.DoAnalysisByPedrlLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_PDERL, out double demMinX, out double demMinY, out double perX, out double perY);
var PDERLTime = DateTime.Now - date;
date = DateTime.Now;
demAnalysisService.Analysis.DoAnalysisByXPderlLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_XPDERL, out double utmLeftLon2, out double utmBottomLat2, out double perX2, out double perY2);
var XPDERLTime = DateTime.Now - date;
date = DateTime.Now;
demAnalysisService.Analysis.DoAnalysisByRpLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_RefF, out double utmLeftLon5, out double utmBottomLat5, out double perX5, out double perY5);
var RefFTime = DateTime.Now - date;
date = DateTime.Now;
demAnalysisService.Analysis.DoAnalysisByXDrawLonLat(lon, lat, toLon, toLat, dh,
out int[,] result_XDraw, out double utmLeftLon3, out double utmBottomLat3, out double perX3, out double perY3);
var XDrawTime = DateTime.Now - date;
date = DateTime.Now;
//R3算法
demAnalysisService.Analysis.DoAnalysisByR3LonLat(lon, lat, toLon, toLat, dh,
out int[,] result_R3, out double utmLeftLon4, out double utmBottomLat4, out double perX4, out double perY4);
var R3Time = DateTime.Now - date;
date = DateTime.Now;
int lonCount = result_R3.GetLength(0);
int latCount = result_R3.GetLength(1);
int AllPointCount = lonCount * latCount;
//获取通视率
double VisibleRate = GetVisibleRate(result_R3);