等高线自适应分割

根据已知数据,最大值最小值和计划设定的等高线条数,获取最合适的,等高线分割和等高线条数;

采用缺省的,0.1,0.2,0.25,0.5的整数倍分割

 1  /// <summary>
 2         /// 计算等高线分割
 3         /// </summary>
 4         /// <param name="cormax">数据最大值</param>
 5         /// <param name="cormin">数据最小值</param>
 6         /// <param name="cornumber">计划设定等高线条数</param>
 7         private void Standard(ref double cormax, ref double cormin, ref double cornumber)
 8         {
 9             double corstep, tmpstep, tmpnumber, temp, extranumber;
10             if (cormax <= cormin)
11                 return;
12             corstep = (cormax - cormin) / cornumber;
13             if (Math.Pow(10, (int)(Math.Log(corstep) / Math.Log(10))) == corstep)
14             {
15                 temp = Math.Pow(10, (int)(Math.Log(corstep) / Math.Log(10)));
16             }
17             else
18             {
19                 temp = Math.Pow(10, ((int)(Math.Log(corstep) / Math.Log(10)) + 1));
20             }
21             tmpstep = Math.Round(corstep / temp, 6);
22             //选取规范步长
23             if (tmpstep >= 0 && tmpstep <= 0.1)
24             {
25                 tmpstep = 0.1;
26             }
27             else if (tmpstep >= 0.100001 && tmpstep <= 0.2)
28             {
29                 tmpstep = 0.2;
30             }
31             else if (tmpstep >= 0.200001 && tmpstep <= 0.25)
32             {
33                 tmpstep = 0.25;
34             }
35             else if (tmpstep >= 0.250001 && tmpstep <= 0.5)
36             {
37                 tmpstep = 0.5;
38             }
39             else
40             {
41                 tmpstep = 1;
42             }
43             tmpstep = tmpstep * temp;
44             if ((int)(cormin / tmpstep) != (cormin / tmpstep))
45             {
46                 if (cormin < 0)
47                 {
48                     cormin = (-1) * Math.Ceiling(Math.Abs(cormin / tmpstep)) * tmpstep;
49                 }
50                 else
51                 {
52                     cormin = (int)(Math.Abs(cormin / tmpstep)) * tmpstep;
53                 }
54 
55             }
56             if ((int)(cormax / tmpstep) != (cormax / tmpstep))
57             {
58                 cormax = (int)(cormax / tmpstep + 1) * tmpstep;
59             }
60             tmpnumber = (cormax - cormin) / tmpstep;
61             if (tmpnumber < cornumber)
62             {
63                 extranumber = cornumber - tmpnumber;
64                 tmpnumber = cornumber;
65                 if (extranumber % 2 == 0)
66                 {
67                     cormax = cormax + tmpstep * (int)(extranumber / 2);
68                 }
69                 else
70                 {
71                     cormax = cormax + tmpstep * (int)(extranumber / 2 + 1);
72                 }
73                 cormin = cormin - tmpstep * (int)(extranumber / 2);
74             }
75             cornumber = tmpnumber;
76         }
View Code

 采用数据间隔的下一位作为最小分割位,执行等高线分割操作

 1  /// <summary>
 2         /// 计算等高线分割
 3         /// </summary>
 4         /// <param name="cormax"></param>
 5         /// <param name="cormin"></param>
 6         /// <param name="cornumber"></param>
 7         private void Standard2(ref double cormax, ref double cormin, ref int cornumber)
 8         {
 9             decimal max = (decimal)cormax;
10             if (cormax > 0)
11             {
12                 double lmax = Math.Log10(cormax);
13                 int fmax = (int)Math.Floor(lmax - 1);
14                 double pmax = Math.Pow(10, fmax);
15                 max = (decimal)Math.Ceiling(cormax / pmax) * (decimal)pmax;
16             }
17             else if (cormax < 0)
18             {
19                 double lmax = Math.Log10(-cormax);
20                 int fmax = (int)Math.Floor(lmax - 1);
21                 double pmax = Math.Pow(10, fmax);
22                 max = (decimal)Math.Floor(cormax / pmax) * (decimal)pmax;
23             }
24             double corstep = (cormax - cormin) / (cornumber - 1);
25 
26             double lstep = Math.Log10(corstep);
27             int fstep = (int)Math.Floor(lstep - 1);
28             double pstep = Math.Pow(10, fstep);
29             decimal step = (decimal)Math.Ceiling(corstep / pstep) * (decimal)pstep;
30 
31             decimal min = max - (step * cornumber);
32             cormax = (double)max;
33             cormin = (double)min;
34         }
View Code
敲击键盘,创造价值
原文地址:https://www.cnblogs.com/weiweiboqi/p/14576345.html