-
Notifications
You must be signed in to change notification settings - Fork 1
/
WWSalinityProvider.cs
62 lines (46 loc) · 1.5 KB
/
WWSalinityProvider.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
using System;
using System.Collections.Generic;
namespace UCNLSalinity
{
public class WWSalinityProvider
{
#region Properties
SettingsProviderXML<List<MSDE>> dataProvider;
#endregion
#region Constructor
public WWSalinityProvider(string salinityDBFileName)
{
dataProvider = new SettingsProviderXML<List<MSDE>>();
dataProvider.Load(salinityDBFileName);
}
#endregion
#region Methods
public List<MSDE> GetDB()
{
return dataProvider.Data;
}
public double GetNearestSalinity(double lat, double lon, out double nlat, out double nlon)
{
double dLat = double.MaxValue;
double dLon = double.MaxValue;
int idx = 0;
double minD = double.MaxValue;
nlat = 0;
nlon = 0;
for (int i = 0; i < dataProvider.Data.Count; i++)
{
dLat = Math.Abs(lat - dataProvider.Data[i].Lat);
dLon = Math.Abs(lon - dataProvider.Data[i].Lon);
if (dLon + dLat < minD)
{
minD = dLon + dLat;
idx = i;
nlat = dataProvider.Data[i].Lat;
nlon = dataProvider.Data[i].Lon;
}
}
return dataProvider.Data[idx].Sal;
}
#endregion
}
}