- 积分
- 55940
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
发表于 2015-11-4 19:15:04
|
显示全部楼层
本帖最后由 MeteoInfo 于 2015-11-4 19:16 编辑
例子:
- public StationData GetStationData(int timeIdx, int varIdx, int levelIdx)
- {
- StreamReader sr = new StreamReader(this.FileName, System.Text.Encoding.UTF8);
- List<string[]> dataList = new List<string[]>();
- sr.ReadLine();
- string line = sr.ReadLine();
- while (line != null)
- {
- if (line == String.Empty)
- {
- line = sr.ReadLine();
- continue;
- }
- dataList.Add(line.Split(','));
- line = sr.ReadLine();
- }
- sr.Close();
- StationData stationData = new StationData();
- List<string> stations = new List<string>();
- string stName;
- int i;
- double lon, lat;
- double t;
- t = 0;
- string[] dataArray;
- double[,] DiscreteData = new double[3, dataList.Count];
- double minX, maxX, minY, maxY;
- minX = 0;
- maxX = 0;
- minY = 0;
- maxY = 0;
- //Get real variable index
- int varIdx1 = FieldList.IndexOf(this.Variables[varIdx].Name);
- String vstr;
- for (i = 0; i < dataList.Count; i++)
- {
- dataArray = dataList[i];
- stName = dataArray[0];
- lon = double.Parse(dataArray[1]);
- lat = double.Parse(dataArray[2]);
- vstr = dataArray[varIdx1];
- if (String.IsNullOrEmpty(vstr))
- t = stationData.MissingValue;
- else
- t = double.Parse(dataArray[varIdx1]);
- //if (lon < 0)
- //{
- // lon += 360;
- //}
- //Initialize data
- DiscreteData[0, i] = lon;
- DiscreteData[1, i] = lat;
- DiscreteData[2, i] = t;
- stations.Add(stName);
- if (i == 0)
- {
- minX = lon;
- maxX = minX;
- minY = lat;
- maxY = minY;
- }
- else
- {
- if (minX > lon)
- {
- minX = lon;
- }
- else if (maxX < lon)
- {
- maxX = lon;
- }
- if (minY > lat)
- {
- minY = lat;
- }
- else if (maxY < lat)
- {
- maxY = lat;
- }
- }
- }
- Extent dataExtent = new Extent();
- dataExtent.minX = minX;
- dataExtent.maxX = maxX;
- dataExtent.minY = minY;
- dataExtent.maxY = maxY;
- stationData.Data = DiscreteData;
- stationData.DataExtent = dataExtent;
- stationData.Stations = stations;
- return stationData;
- }
复制代码
|
|