public static ObservationInfo[] ReadFile(string file) { if (string.IsNullOrEmpty(file) || !File.Exists(file)) { return(null); } string[] content = File.ReadAllLines(file, Encoding.Default); if (content == null || content.Length == 0) { return(null); } List <ObservationInfo> infos = new List <ObservationInfo>(); ObservationInfo wi = null; string[] values = null; foreach (string item in content) { values = item.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (values == null || values.Length == 0 || values.Length != 4) { continue; } float chazhi = 0; float.TryParse(values[3], out chazhi); wi = new ObservationInfo(values[0], GetLonLat(values[1]), GetLonLat(values[2]), chazhi); if (wi.Lon == float.MinValue || wi.Lat == float.MinValue) { continue; } infos.Add(wi); } return(infos.Count == 0?null:infos.ToArray()); }
private void CalcRowCol(ObservationInfo watchInfo, out int row, out int col) { row = col = -1; col = (int)Math.Floor((watchInfo.Lon - _arp.DataProvider.CoordEnvelope.MinX) / _arp.DataProvider.ResolutionX); if (col < 0) { return; } row = (int)Math.Floor((_arp.DataProvider.CoordEnvelope.MaxY - watchInfo.Lat) / _arp.DataProvider.ResolutionY); }
private void btnAverValue_Click(object sender, EventArgs e) { ObservationInfo[] infos = null; if (!string.IsNullOrEmpty(_observationFile) && File.Exists(_observationFile)) { infos = ObservationInfo.ReadFile(_observationFile); } if (infos == null) { txtAverValue.Text = "0"; return; } txtAverValue.Text = CalcAverValue(infos).ToString(); if (_handler != null) { _handler(GetArgumentValue()); } MessageBox.Show(ObservationPintInfo, "均值计算", MessageBoxButtons.OK); }