/// <summary> /// Read grid data /// </summary> /// <returns>grid data</returns> public double[,] ReadData() { double[,] gridData = new double[YNum, XNum]; StreamReader sr = new StreamReader(FileName); string[] dataArray; List <string> dataList = new List <string>(); int LastNonEmpty, i, j; string aLine, wholeStr; for (i = 0; i < 6; i++) { sr.ReadLine(); } aLine = sr.ReadLine().Trim(); string aStr = aLine.Split()[0]; wholeStr = sr.ReadToEnd(); sr.Close(); if (MIMath.IsNumeric(aStr)) { wholeStr = aLine + " " + wholeStr; } dataArray = wholeStr.Split(); LastNonEmpty = -1; for (i = 0; i < dataArray.Length; i++) { if (dataArray[i] != string.Empty) { LastNonEmpty++; dataList.Add(dataArray[i]); } } for (i = 0; i < YNum; i++) { for (j = 0; j < XNum; j++) { gridData[i, j] = double.Parse(dataList[i * XNum + j]); } } double[,] newGridData = new double[YNum, XNum]; for (i = 0; i < YNum; i++) { for (j = 0; j < XNum; j++) { newGridData[i, j] = gridData[YNum - 1 - i, j]; } } return(newGridData); }
private void CB_Field_SelectedIndexChanged(object sender, EventArgs e) { if (MIMath.IsNumeric(_layer.AttributeTable.Table.Columns[CB_Field.Text])) { CHB_AutoDecimal.Enabled = true; } else { CHB_AutoDecimal.Enabled = false; } }
private void SetFieldByLegendType(LegendType aLT) { if (_mapLayer.LayerType == LayerTypes.VectorLayer) { VectorLayer aLayer = (VectorLayer)_mapLayer; switch (aLT) { case LegendType.SingleSymbol: CB_Field.Enabled = false; CB_Field.Text = "<None>"; CreateLegendScheme(aLT, ""); break; case LegendType.UniqueValue: CB_Field.Enabled = true; CB_Field.Items.Clear(); foreach (string fn in aLayer.GetFieldNameList()) { CB_Field.Items.Add(fn); } CB_Field.Text = "<None>"; break; case LegendType.GraduatedColor: CB_Field.Enabled = true; CB_Field.Items.Clear(); for (int i = 0; i < aLayer.NumFields; i++) { if (MIMath.IsNumeric(aLayer.GetField(i))) { CB_Field.Items.Add(aLayer.GetFieldName(i)); } } CB_Field.Text = "<None>"; break; } } }
private void AfterCellEdit() { if (TB_Editor.Tag.ToString() == "Value") { string aValue = TB_Editor.Text.Trim(); double sValue, eValue; int aIdx; aIdx = aValue.IndexOf("-"); if (aIdx > 0) { if (aValue.Substring(aIdx - 1, 1) == "E") { aIdx = aValue.IndexOf("-", aIdx + 1); } sValue = Convert.ToDouble(aValue.Substring(0, aIdx).Trim()); eValue = Convert.ToDouble(aValue.Substring(aIdx + 1).Trim()); aValue = aValue.Substring(0, aIdx).Trim() + " - " + aValue.Substring(aIdx + 1).Trim(); _curBreak.StartValue = sValue; _curBreak.EndValue = eValue; } else if (aIdx == 0) { aIdx = aValue.Substring(1).IndexOf("-"); if (aIdx > 0) { aIdx += 1; sValue = Convert.ToDouble(aValue.Substring(0, aIdx).Trim()); eValue = Convert.ToDouble(aValue.Substring(aIdx + 1).Trim()); aValue = aValue.Substring(0, aIdx).Trim() + " - " + aValue.Substring(aIdx + 1).Trim(); } else { sValue = Convert.ToDouble(aValue); eValue = sValue; } _curBreak.StartValue = sValue; _curBreak.EndValue = eValue; } else { if (MIMath.IsNumeric(aValue)) { sValue = Convert.ToDouble(aValue); eValue = sValue; } _curBreak.StartValue = aValue; _curBreak.EndValue = aValue; } _curBreak.Caption = aValue; } else if (TB_Editor.Tag.ToString() == "Label") { string caption = TB_Editor.Text.Trim(); _curBreak.Caption = caption; } TB_Editor.Visible = false; this.Validate(); }
/// <summary> /// Read SYNOP data info /// </summary> /// <param name="dataFN">METAR data file name</param> public override void ReadDataInfo(string dataFN) { FileName = dataFN; //Read stations StreamReader sr = new StreamReader(StFileName); string aLine; string[] dataArray; List <string> dataList = new List <string>(); List <string> stIDList = new List <string>(); List <string[]> stPosList = new List <string[]>(); int i, LastNonEmpty, dataNum; sr.ReadLine(); dataNum = 0; while (true) { aLine = sr.ReadLine(); if (aLine == null) { break; } if (aLine == "") { continue; } dataArray = aLine.Split(','); stIDList.Add(dataArray[1]); stPosList.Add(new string[2] { dataArray[5], dataArray[4] }); dataNum += 1; } sr.Close(); //Read data sr = new StreamReader(dataFN); List <List <string> > disDataList = new List <List <string> >(); List <string> stList = new List <string>(); string reportType = "AAXX", str, stID; DateTime toDay = DateTime.Now; DateTime aTime; string windSpeedIndicator = "/"; int stIdx; bool isSetTime = true; while (true) { aLine = sr.ReadLine(); if (aLine == null) { break; } aLine = aLine.Trim(); if (aLine == string.Empty) { continue; } if (aLine.Length == 3 && MIMath.IsNumeric(aLine)) //Skip group number { sr.ReadLine(); //Skip 090000 line continue; } //if (aLine.Substring(0, 2) == "SI" || aLine.Substring(0,2) == "SN") //Skip "SI????" line // continue; if (aLine.Length < 4) { continue; } switch (aLine.Substring(0, 4)) { case "AAXX": //A SYNOP report from a fixed land station is identified by the symbolic letters MiMiMjMj = AAXX reportType = "AAXX"; str = aLine.Substring(aLine.Length - 5, 5); if (isSetTime) { aTime = new DateTime(toDay.Year, toDay.Month, int.Parse(str.Substring(0, 2)), int.Parse(str.Substring(2, 2)), 0, 0); DateTime = aTime; isSetTime = false; } windSpeedIndicator = str.Substring(str.Length - 1, 1); break; case "BBXX": //A SHIP report from a sea station is identified by the symbolic letters MiMiMjMj = BBXX reportType = "BBXX"; break; case "OOXX": //A SYNOP MOBIL report from a mobile land station is identified by the symbolic letters MiMiMjMj = OOXX reportType = "OOXX"; break; default: //Data line while (aLine.Substring(aLine.Length - 1, 1) != "=") { str = sr.ReadLine(); if (str == null) { break; } aLine = aLine + " " + sr.ReadLine(); } dataArray = aLine.Split(); LastNonEmpty = -1; dataList = new List <string>(); for (i = 0; i < dataArray.Length; i++) { if (dataArray[i] != string.Empty) { LastNonEmpty++; dataList.Add(dataArray[i]); } } stID = dataList[0]; switch (reportType) { case "AAXX": if (dataList.Count > 2) { stIdx = stIDList.IndexOf(stID); if (stIdx >= 0) { dataList.Insert(0, windSpeedIndicator); dataList.Insert(0, reportType); dataList.Insert(0, stPosList[stIdx][1]); dataList.Insert(0, stPosList[stIdx][0]); disDataList.Add(dataList); } } break; case "BBXX": case "OOXX": if (dataList.Count > 5) { if (dataList[2].Contains("/") || dataList[3].Contains("/")) { continue; } if (dataList[2].Substring(0, 2) != "99") { continue; } str = dataList[1]; windSpeedIndicator = str.Substring(str.Length - 1, 1); float lat = float.Parse(dataList[2].Substring(2)) / 10; float lon = float.Parse(dataList[3].Substring(1)) / 10; if (lat > 90 || lon > 180) { continue; } switch (dataList[3].Substring(0, 1)) { case "1": //North east break; case "3": //South east lat = -lat; break; case "5": //South west lat = -lat; lon = -lon; break; case "7": //North west lon = -lon; break; } dataList.Insert(0, windSpeedIndicator); dataList.Insert(0, reportType); dataList.Insert(0, lat.ToString()); dataList.Insert(0, lon.ToString()); disDataList.Add(dataList); } break; } break; } } sr.Close(); StationNum = disDataList.Count; DataList = disDataList; Dimension tdim = new Dimension(DimensionType.T); tdim.DimValue.Add(DataConvert.ToDouble(DateTime)); tdim.DimLength = 1; List <Variable> vars = new List <Variable>(); foreach (string vName in VarList) { Variable var = new Variable(); var.Name = vName; var.SetDimension(tdim); var.IsStation = true; vars.Add(var); } this.Variables = vars; }
private double GetDataValue(List <string> dataList, int vIdx, int sIdx, string windSpeedIndicator) { double value = MissingValue; string str; int i; switch (vIdx) { case 0: //Visibility str = dataList[sIdx]; if (str.Length != 5) { break; } str = str.Substring(3); if (str.Contains("/")) { break; } value = int.Parse(str); if (value <= 50) { value = value / 10; } else if (value >= 56 && value <= 80) { value = value - 50; } else if (value >= 81 && value <= 89) { value = 30 + (value - 80) * 5; } else if (value >= 90 && value <= 99) { switch ((int)value) { case 90: value = 0.04; break; case 91: value = 0.05; break; case 92: value = 0.2; break; case 93: value = 0.5; break; case 94: value = 1; break; case 95: value = 2; break; case 96: value = 4; break; case 97: value = 10; break; case 98: value = 20; break; case 99: value = 50; break; } } break; case 1: //Cloud cover str = dataList[sIdx + 1]; if (str.Length != 5) { break; } str = str.Substring(0, 1); if (str == "/") { break; } value = int.Parse(str); break; case 2: //Wind direction str = dataList[sIdx + 1]; if (str.Length != 5) { break; } str = str.Substring(1, 2); if (str == "//") { break; } value = int.Parse(str) * 10; if (value > 360) { value = 0; } break; case 3: //Wind speed if (windSpeedIndicator == "/") { break; } str = dataList[sIdx + 1]; if (str.Length != 5) { break; } str = str.Substring(3); if (str.Contains("/")) { break; } if (str == "99") { str = dataList[sIdx + 2].Substring(2); if (str.Contains("/")) { break; } value = int.Parse(str); } else { value = int.Parse(str); } if (windSpeedIndicator == "3" || windSpeedIndicator == "4") { value = value * 0.51444; //Convert KT to MPS } break; case 4: //Temperature str = string.Empty; for (i = sIdx + 2; i < dataList.Count; i++) { if (dataList[i].Length == 5 && dataList[i].Substring(0, 1) == "1") { str = dataList[i]; break; } } if (str != string.Empty) { if (str.Contains("/")) { break; } string sign = str.Substring(1, 1); value = double.Parse(str.Substring(2)) / 10; if (sign == "1") { value = -value; } } break; case 5: //Dew point str = string.Empty; for (i = sIdx + 2; i < dataList.Count; i++) { if (dataList[i].Length == 5 && dataList[i].Substring(0, 1) == "2") { str = dataList[i]; break; } } if (str != string.Empty) { if (str.Contains("/")) { break; } string sign = str.Substring(1, 1); if (sign == "9") //Relative humidity { break; } value = double.Parse(str.Substring(2)) / 10; if (sign == "1") { value = -value; } } break; case 6: //Pressure str = string.Empty; for (i = sIdx + 2; i < dataList.Count; i++) { if (dataList[i].Length == 5 && dataList[i].Substring(0, 1) == "3") { str = dataList[i]; break; } } if (str != string.Empty) { if (str.Contains("/")) { break; } if (!MIMath.IsNumeric(str.Substring(1))) { break; } value = double.Parse(str.Substring(1)) / 10; value = value / 10; if (value < 500) { value += 1000; } } break; case 7: //Precipitation str = string.Empty; for (i = sIdx + 2; i < dataList.Count; i++) { if (dataList[i].Length == 5 && dataList[i].Substring(0, 1) == "6") { str = dataList[i]; break; } } if (str != string.Empty) { if (str.Contains("/")) { break; } value = double.Parse(str.Substring(1, 3)); if (value >= 990) { value = value - 990; } } break; case 8: //Weather str = string.Empty; for (i = sIdx + 2; i < dataList.Count; i++) { if (dataList[i].Length == 5 && dataList[i].Substring(0, 1) == "7") { str = dataList[i]; break; } } if (str != string.Empty) { if (str.Substring(1, 2).Contains("/")) { break; } value = int.Parse(str.Substring(1, 2)); } break; } return(value); }
/// <summary> /// Read data info /// </summary> /// <param name="aFile">file path</param> public override void ReadDataInfo(string aFile) { FileStream fs = new FileStream(aFile, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs, Encoding.Default); //Read file head //string header = System.Text.ASCIIEncoding.ASCII.GetString(br.ReadBytes(128)); string header = System.Text.Encoding.Default.GetString(br.ReadBytes(128)); string[] dataArray = header.Split(); int LastNonEmpty = -1; List <string> dataList = new List <string>(); for (int i = 0; i < dataArray.Length; i++) { if (dataArray[i] != string.Empty) { LastNonEmpty++; dataList.Add(dataArray[i]); } } FileName = aFile; Description = dataList[2]; //Time = DateTime.Parse(dataList[3] + "-" + dataList[4] + "-" + dataList[5] + " " + // dataList[6] + ":00"); int aYear = int.Parse(dataList[3]); if (aYear < 100) { if (aYear > 50) { aYear = 1900 + aYear; } else { aYear = 2000 + aYear; } } Time = new DateTime(aYear, int.Parse(dataList[4]), int.Parse(dataList[5]), int.Parse(dataList[6]), 0, 0); XNum = int.Parse(dataList[7]); YNum = int.Parse(dataList[8]); Lon_LB = double.Parse(dataList[9]); Lat_LB = double.Parse(dataList[10]); ProjOption = int.Parse(dataList[11]); ZoomFactor = double.Parse(dataList[12]); ImageType = int.Parse(dataList[13]); TableName = dataList[14]; if (MIMath.IsNumeric(dataList[15]) && MIMath.IsNumeric(dataList[16])) { Lon_Center = double.Parse(dataList[15]); Lat_Center = double.Parse(dataList[16]); if (Lon_Center > 180) { Lon_Center = Lon_Center / 100; } if (Lat_Center > 90) { Lat_Center = Lat_Center / 100; } } else { Lon_Center = 110.0; Lat_Center = 30.0; } //Read image data int length = (int)fs.Length - 128; ImageBytes = br.ReadBytes(length); //Set projection parameters GetProjectionInfo(); CalCoordinate(); br.Close(); fs.Close(); Dimension tdim = new Dimension(DimensionType.T); tdim.DimValue.Add(DataConvert.ToDouble(Time)); tdim.DimLength = 1; this.TimeDimension = tdim; Dimension xdim = new Dimension(DimensionType.X); xdim.SetValues(X); Dimension ydim = new Dimension(DimensionType.Y); ydim.SetValues(Y); Variable var = new Variable(); var.Name = "var"; var.SetDimension(tdim); var.SetDimension(ydim); var.SetDimension(xdim); List <Variable> vars = new List <Variable>(); vars.Add(var); this.Variables = vars; }
private void Initialize() { PG_General.SelectedObject = _mapLayer.GetPropertyObject(); TabControl_Prop.TabPages.Clear(); TabControl_Prop.TabPages.Add(TabPage_General); switch (_mapLayer.LayerType) { case LayerTypes.VectorLayer: case LayerTypes.RasterLayer: TabControl_Prop.TabPages.Add(TabPage_Legend); _legendScheme = (LegendScheme)_mapLayer.LegendScheme.Clone(); legendSchemeControl1.Update(_mapLayer, _mapLayer.LegendScheme); break; case LayerTypes.ImageLayer: break; } if (_mapLayer.LayerType == LayerTypes.VectorLayer) { switch (_mapLayer.ShapeType) { case ShapeTypes.Point: case ShapeTypes.PointZ: case ShapeTypes.Polygon: TabControl_Prop.TabPages.Add(TabPage_Chart); VectorLayer aLayer = (VectorLayer)_mapLayer; if (_mapLayer.ShapeType == ShapeTypes.Polygon) { CB_ChartType.Items.Clear(); CB_ChartType.Items.Add(ChartTypes.BarChart.ToString()); CB_ChartType.Items.Add(ChartTypes.PieChart.ToString()); } else { CB_ChartType.Items.Clear(); CB_ChartType.Items.Add(ChartTypes.BarChart.ToString()); CB_ChartType.Items.Add(ChartTypes.PieChart.ToString()); //CB_ChartType.Items.Add(ChartTypes.WindVector.ToString()); //CB_ChartType.Items.Add(ChartTypes.WindBarb.ToString()); //CB_ChartType.Items.Add(ChartTypes.StationModel.ToString()); } CB_ChartType.Text = aLayer.ChartSet.ChartType.ToString(); //Add fields CLB_Fields.Items.Clear(); for (int i = 0; i < aLayer.NumFields; i++) { if (MIMath.IsNumeric(aLayer.GetField(i))) { string fn = aLayer.GetFieldName(i); CLB_Fields.Items.Add(fn); if (aLayer.ChartSet.FieldNames.Contains(fn)) { CLB_Fields.SetItemChecked(CLB_Fields.Items.Count - 1, true); } } } TB_BarWidth.Text = aLayer.ChartSet.BarWidth.ToString(); TB_MaxSize.Text = aLayer.ChartSet.MaxSize.ToString(); TB_MinSize.Text = aLayer.ChartSet.MinSize.ToString(); TB_XShift.Text = aLayer.ChartSet.XShift.ToString(); TB_YShift.Text = aLayer.ChartSet.YShift.ToString(); CHB_Collision.Checked = aLayer.ChartSet.AvoidCollision; //Set align type CB_Align.Items.Clear(); foreach (string align in Enum.GetNames(typeof(AlignType))) { CB_Align.Items.Add(align); } CB_Align.Text = aLayer.ChartSet.AlignType.ToString(); CHB_View3D.Checked = aLayer.ChartSet.View3D; TB_Thickness.Text = aLayer.ChartSet.Thickness.ToString(); legendView_Chart.LegendScheme = aLayer.ChartSet.LegendScheme; break; } } }