/// <summary> /// Override operator less than or equal between a station data and a double data /// </summary> /// <param name="aStData">a station data</param> /// <param name="aData">a double data</param> /// <returns>result station data</returns> public static StationData operator <=(StationData aStData, double aData) { StationData cStData = new StationData(aStData); for (int i = 0; i < aStData.Stations.Count; i++) { double aValue = aStData.Data[2, i]; if (MIMath.DoubleEquals(aValue, aStData.MissingValue)) { cStData.Data[2, i] = aStData.MissingValue; } else { if (aValue <= aData) { cStData.Data[2, i] = 1; } else { cStData.Data[2, i] = 0; } } } return(cStData); }
/// <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); }
/// <summary> /// Set points /// </summary> /// <param name="points">points</param> public void SetPoints(PointF[] points) { _pointList = new List <PointD>(); foreach (PointF aP in points) { _pointList.Add(new PointD(aP.X, aP.Y)); } _extent = MIMath.GetPointsExtent(_pointList); }
private Image getImageFromGridData(GridData gdata, LegendScheme als) { int width, height, breakNum; width = gdata.XNum; height = gdata.YNum; breakNum = als.BreakNum; double[] breakValue = new double[breakNum]; Color[] breakColor = new Color[breakNum]; Color undefColor = Color.White; for (int i = 0; i < breakNum; i++) { breakValue[i] = Convert.ToDouble(als.LegendBreaks[i].EndValue); breakColor[i] = als.LegendBreaks[i].Color; if (als.LegendBreaks[i].IsNoData) { undefColor = als.LegendBreaks[i].Color; } } Color defaultColor = breakColor[breakNum - 1]; //Set default as last color Bitmap aBitmap = new Bitmap(width, height); aBitmap.MakeTransparent(); double oneValue; Color oneColor = defaultColor; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { oneValue = gdata.Data[i, j]; if (MIMath.DoubleEquals(oneValue, gdata.MissingValue)) { oneColor = undefColor; } else { oneColor = defaultColor; for (int k = 0; k < breakNum - 1; k++) { if (oneValue < breakValue[k]) { oneColor = breakColor[k]; break; } } } aBitmap.SetPixel(j, height - i - 1, oneColor); } } Image aImage = (Image)aBitmap; return(aImage); }
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; } }
/// <summary> /// Update image /// </summary> public void UpdateImage() { int xNum = GridData.XNum; int yNum = GridData.YNum; byte[] imageBytes = new byte[xNum * yNum]; for (int i = 0; i < yNum; i++) { for (int j = 0; j < xNum; j++) { int value = -1; int b; for (b = 0; b < LegendScheme.LegendBreaks.Count - 1; b++) { ColorBreak aCB = LegendScheme.LegendBreaks[b]; if (aCB.StartValue.ToString() == aCB.EndValue.ToString()) { if (GridData.Data[i, j] == double.Parse(aCB.StartValue.ToString())) { value = b; break; } } else { if (GridData.Data[i, j] >= double.Parse(aCB.StartValue.ToString()) && GridData.Data[i, j] < double.Parse(aCB.EndValue.ToString())) { value = b; break; } } } if (value == -1) { value = b; if (LegendScheme.LegendBreaks[LegendScheme.BreakNum - 1].IsNoData) { if (!MIMath.DoubleEquals(GridData.Data[i, j], LegendScheme.MissingValue)) { value = b - 1; } } } imageBytes[i * xNum + j] = (byte)value; } } Image = DrawMeteoData.CreateBitmap(imageBytes, xNum, yNum); List <Color> colors = LegendScheme.GetColors(); DrawMeteoData.SetPalette(colors, Image); }
/// <summary> /// Insert a graphic /// </summary> /// <param name="index">index</param> /// <param name="aGraphic">graphic</param> public void Insert(int index, Graphic aGraphic) { _graphicList.Insert(index, aGraphic); //Update extent if (_graphicList.Count == 1) { _extent = aGraphic.Shape.Extent; } else { _extent = MIMath.GetLagerExtent(_extent, aGraphic.Shape.Extent); } }
/// <summary> /// Add a graphic /// </summary> /// <param name="aGraphic">graphic</param> public void Add(Graphic aGraphic) { _graphicList.Add(aGraphic); //Update extent if (_graphicList.Count == 1) { _extent = aGraphic.Shape.Extent; } else { _extent = MIMath.GetLagerExtent(_extent, aGraphic.Shape.Extent); } }
/// <summary> /// Determine if the polyline is closed /// </summary> /// <returns>if is closed</returns> public bool IsClosed() { PointD sPoint = _pointList[0]; PointD ePoint = _pointList[_pointList.Count - 1]; if (MIMath.DoubleEquals(sPoint.X, ePoint.X) && MIMath.DoubleEquals(sPoint.Y, ePoint.Y)) { return(true); } else { return(false); } }
private void UpdatePartsPoints() { _numParts = 0; _points = new List <PointD>(); List <int> partList = new List <int>(); for (int i = 0; i < _polyLines.Count; i++) { _numParts += 1; partList.Add(_points.Count); _points.AddRange(_polyLines[i].PointList); } parts = partList.ToArray(); Extent = MIMath.GetPointsExtent(_points); }
private void UpdatePartsPoints() { _numParts = 0; _points = new List <PointD>(); List <int> partList = new List <int>(); for (int i = 0; i < _polygons.Count; i++) { _numParts += _polygons[i].RingNumber; for (int j = 0; j < _polygons[i].RingNumber; j++) { partList.Add(_points.Count); _points.AddRange(_polygons[i].Rings[j]); } } parts = partList.ToArray(); Extent = MIMath.GetPointsExtent(_points); }
private Image getImageFromGridData_Bak1(GridData gdata, LegendScheme als) { int width, height, breakNum; width = gdata.XNum; height = gdata.YNum; breakNum = als.BreakNum; Color defaultColor = als.LegendBreaks[breakNum - 1].Color; //默认颜色为最后一个颜色 Bitmap aBitmap = new Bitmap(width, height); aBitmap.MakeTransparent(); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { double oneValue = gdata.Data[i, j]; Color oneColor = defaultColor; for (int k = 0; k < breakNum; k++) { if (als.LegendBreaks[k].StartValue.ToString() == als.LegendBreaks[k].EndValue.ToString()) { if (MIMath.DoubleEquals(oneValue, Double.Parse(als.LegendBreaks[k].EndValue.ToString()))) { oneColor = als.LegendBreaks[k].Color; break; } } else { if (oneValue >= Double.Parse(als.LegendBreaks[k].StartValue.ToString()) && oneValue < Double.Parse(als.LegendBreaks[k].EndValue.ToString())) { oneColor = als.LegendBreaks[k].Color; break; } } } aBitmap.SetPixel(j, height - i - 1, oneColor); } } Image aImage = (Image)aBitmap; return(aImage); }
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; } } }
/// <summary> /// Read Lon/Lat station data info /// </summary> /// <param name="aFile">data file name</param> public override void ReadDataInfo(string aFile) { FileName = aFile; //Read data int i; StreamReader sr = new StreamReader(aFile, System.Text.Encoding.UTF8); string[] dataArray, fieldArray; string aLine = sr.ReadLine(); //Title fieldArray = aLine.Split(','); if (fieldArray.Length < 3) { MessageBox.Show("The data should have at least four fields!", "Error"); return; } FieldList = new List <string>(fieldArray.Length); FieldList.AddRange(fieldArray); //Judge field type aLine = sr.ReadLine(); //First line dataArray = aLine.Split(','); List <Variable> variables = new List <Variable>(); for (i = 3; i < dataArray.Length; i++) { if (MIMath.IsNumeric_1(dataArray[i])) { Variable var = new Variable(); var.Name = fieldArray[i]; var.IsStation = true; variables.Add(var); } } this.Variables = variables; sr.Close(); }
/// <summary> /// Save as CSV data file /// </summary> /// <param name="aFile">file path</param> /// <param name="fieldName">data field name</param> /// <param name="saveUndefData">if save undefine data</param> public void SaveAsCSVFile(string aFile, string fieldName, bool saveUndefData) { StreamWriter sw = new StreamWriter(aFile, false, Encoding.Default); string aStr = "Stid,Latitude,Lontitude," + fieldName; sw.WriteLine(aStr); for (int i = 0; i < Data.GetLength(1); i++) { if (!saveUndefData) { if (MIMath.DoubleEquals(Data[2, i], MissingValue)) { continue; } } aStr = Stations[i] + "," + Data[0, i].ToString() + "," + Data[1, i].ToString() + "," + Data[2, i].ToString(); sw.WriteLine(aStr); } sw.Close(); }
/// <summary> /// Get discrete data from MICAPS 1 data info /// </summary> /// <param name="vIdx">variable index</param> /// <param name="stations">ref stations</param> /// <param name="dataExtent">ref data extent</param> /// <returns>discreted data</returns> public double[,] GetDiscreteData(int vIdx, ref List <string> stations, ref Extent dataExtent) { vIdx += 3; //if (vIdx >= 22) //{ // vIdx += 2; //} string aStid; int i; Single lon, lat, t; List <string> dataList = new List <string>(); double[,] DiscreteData = new double[3, DataList.Count]; Single minX, maxX, minY, maxY; minX = 0; maxX = 0; minY = 0; maxY = 0; stations.Clear(); for (i = 0; i < DataList.Count; i++) { dataList = DataList[i]; aStid = (string)dataList[0]; lon = Convert.ToSingle(dataList[1]); lat = Convert.ToSingle(dataList[2]); t = Convert.ToSingle(dataList[vIdx]); if (vIdx == 8) //Pressure { if (!MIMath.DoubleEquals(t, MissingValue)) { if (t > 800) { t = t / 10 + 900; } else { t = t / 10 + 1000; } } } //if (lon < 0) //{ // lon += 360; //} stations.Add(aStid); DiscreteData[0, i] = lon; DiscreteData[1, i] = lat; DiscreteData[2, i] = t; 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; } } } dataExtent.minX = minX; dataExtent.maxX = maxX; dataExtent.minY = minY; dataExtent.maxY = maxY; return(DiscreteData); }
private void SavGrADSMaskoutFile() { SaveFileDialog SFDlg = new SaveFileDialog(); SFDlg.Filter = "GrADS File (*.ctl)|*.ctl"; if (SFDlg.ShowDialog() == DialogResult.OK) { string aFile = SFDlg.FileName; int i; bool hasSelShape = _currentLayer.HasSelectedShapes(); //Get grid set PolygonShape aPGS = new PolygonShape(); Extent aExtent = new Extent(); int n = 0; for (i = 0; i < _currentLayer.ShapeNum; i++) { aPGS = (PolygonShape)_currentLayer.ShapeList[i]; if (hasSelShape) { if (!aPGS.Selected) { continue; } } if (n == 0) { aExtent = aPGS.Extent; } else { aExtent = MIMath.GetLagerExtent(aExtent, aPGS.Extent); } n += 1; } GridDataSetting aGDP = new GridDataSetting(); aGDP.DataExtent.minX = Math.Floor(aExtent.minX); aGDP.DataExtent.maxX = Math.Ceiling(aExtent.maxX); aGDP.DataExtent.minY = Math.Floor(aExtent.minY); aGDP.DataExtent.maxY = Math.Ceiling(aExtent.maxY); aGDP.XNum = 20; aGDP.YNum = 20; frmGridSet aFrmGS = new frmGridSet(); aFrmGS.SetParameters(aGDP); if (aFrmGS.ShowDialog() == DialogResult.OK) { aFrmGS.GetParameters(ref aGDP); //Show progressbar this.toolStripProgressBar1.Visible = true; this.toolStripProgressBar1.Value = 0; this.Cursor = Cursors.WaitCursor; Application.DoEvents(); //Get grid data double[,] gridData = new double[aGDP.YNum, aGDP.XNum]; int j, p; MeteoInfoC.PointD aPoint = new MeteoInfoC.PointD(); double xSize, ySize; xSize = (aGDP.DataExtent.maxX - aGDP.DataExtent.minX) / (aGDP.XNum - 1); ySize = (aGDP.DataExtent.maxY - aGDP.DataExtent.minY) / (aGDP.YNum - 1); bool isIn = false; for (i = 0; i < aGDP.YNum; i++) { aPoint.Y = aGDP.DataExtent.minY + i * ySize; for (j = 0; j < aGDP.XNum; j++) { aPoint.X = aGDP.DataExtent.minX + j * xSize; isIn = false; for (p = 0; p < _currentLayer.ShapeNum; p++) { aPGS = (PolygonShape)_currentLayer.ShapeList[p]; if (hasSelShape) { if (!aPGS.Selected) { continue; } } if (MIMath.PointInPolygon(aPGS, aPoint)) { isIn = true; break; } } if (isIn) { gridData[i, j] = 1; } else { gridData[i, j] = -1; } } this.toolStripProgressBar1.Value = (i + 1) * 100 / aGDP.YNum; Application.DoEvents(); } //Get GrADS data info string dFile = Path.ChangeExtension(aFile, ".dat"); GrADSDataInfo aDataInfo = new GrADSDataInfo(); aDataInfo.TITLE = "Mask data"; aDataInfo.DSET = dFile; aDataInfo.DTYPE = "GRIDDED"; aDataInfo.XDEF.Type = "LINEAR"; aDataInfo.XDEF.XNum = aGDP.XNum; aDataInfo.XDEF.XMin = (Single)aGDP.DataExtent.minX; aDataInfo.XDEF.XDelt = (Single)(xSize); aDataInfo.YDEF.Type = "LINEAR"; aDataInfo.YDEF.YNum = aGDP.YNum; aDataInfo.YDEF.YMin = (Single)aGDP.DataExtent.minY; aDataInfo.YDEF.YDelt = (Single)(ySize); aDataInfo.ZDEF.Type = "LINEAR"; aDataInfo.ZDEF.ZNum = 1; aDataInfo.ZDEF.SLevel = 1; aDataInfo.ZDEF.ZDelt = 1; aDataInfo.TDEF.Type = "LINEAR"; aDataInfo.TDEF.TNum = 1; aDataInfo.TDEF.STime = DateTime.Now; aDataInfo.TDEF.TDelt = "1mo"; Variable aVar = new Variable(); aVar.Name = "mask"; //aVar.LevelNum = 0; aVar.Units = "99"; aVar.Description = "background mask data"; aDataInfo.VARDEF.AddVar(aVar); //Save files aDataInfo.WriteGrADSCTLFile(); aDataInfo.WriteGrADSData_Grid(dFile, gridData); //Hide progressbar this.toolStripProgressBar1.Visible = false; this.Cursor = Cursors.Default; } } }
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> /// Select graphics by an extent /// </summary> /// <param name="aExtent">extent</param> /// <param name="selectedGraphics">ref selected graphics</param> /// <returns>if selected</returns> public bool SelectGraphics(Extent aExtent, ref GraphicCollection selectedGraphics) { selectedGraphics.GraphicList.Clear(); int i, j; PointD aPoint = new PointD(); aPoint.X = (aExtent.minX + aExtent.maxX) / 2; aPoint.Y = (aExtent.minY + aExtent.maxY) / 2; foreach (Graphic aGraphic in _graphicList) { switch (aGraphic.Shape.ShapeType) { case ShapeTypes.Point: for (i = 0; i < Count; i++) { PointShape aPS = (PointShape)_graphicList[i].Shape; if (MIMath.PointInExtent(aPS.Point, aExtent)) { selectedGraphics.Add(aGraphic); } } break; case ShapeTypes.Polyline: case ShapeTypes.PolylineZ: for (i = 0; i < Count; i++) { PolylineShape aPLS = (PolylineShape)_graphicList[i].Shape; if (MIMath.IsExtentCross(aExtent, aPLS.Extent)) { for (j = 0; j < aPLS.Points.Count; j++) { aPoint = aPLS.Points[j]; if (MIMath.PointInExtent(aPoint, aExtent)) { selectedGraphics.Add(aGraphic); break; } } } } break; case ShapeTypes.Polygon: case ShapeTypes.Rectangle: for (i = Count - 1; i >= 0; i--) { PolygonShape aPGS = (PolygonShape)_graphicList[i].Shape; if (!(aPGS.PartNum > 1)) { if (MIMath.PointInPolygon(aPGS.Points, aPoint)) { selectedGraphics.Add(aGraphic); } } else { for (int p = 0; p < aPGS.PartNum; p++) { ArrayList pList = new ArrayList(); if (p == aPGS.PartNum - 1) { for (int pp = aPGS.parts[p]; pp < aPGS.PointNum; pp++) { pList.Add(aPGS.Points[pp]); } } else { for (int pp = aPGS.parts[p]; pp < aPGS.parts[p + 1]; pp++) { pList.Add(aPGS.Points[pp]); } } if (MIMath.PointInPolygon(pList, aPoint)) { selectedGraphics.Add(aGraphic); break; } } } } break; } } if (selectedGraphics.Count > 0) { return(true); } else { return(false); } }
/// <summary> /// Read WMP map /// </summary> /// <param name="aFile"></param> /// <returns></returns> public static VectorLayer ReadMapFile_WMP(string aFile) { StreamReader sr = new StreamReader(aFile); string aLine; string shapeType; string[] dataArray; int shapeNum; int i, j, pNum; List <PointD> pList = new List <PointD>(); PointD aPoint; ArrayList dataList = new ArrayList(); bool IsTrue = false; string columnName = "Value"; VectorLayer aLayer = new VectorLayer(ShapeTypes.Point); //Read shape type shapeType = sr.ReadLine().Trim(); //Read shape number shapeNum = Convert.ToInt32(sr.ReadLine()); switch (shapeType.ToLower()) { case "point": aLayer = new VectorLayer(ShapeTypes.Point); aLayer.EditAddField(new DataColumn(columnName, typeof(int))); for (i = 0; i < shapeNum; i++) { aLine = sr.ReadLine(); dataArray = aLine.Split(','); aPoint = new PointD(); aPoint.X = Convert.ToDouble(dataArray[0]); aPoint.Y = Convert.ToDouble(dataArray[1]); pList.Add(aPoint); PointShape aPS = new PointShape(); aPS.Value = i; aPS.Point = aPoint; int sNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPS, sNum)) { aLayer.EditCellValue(columnName, sNum, i); } } aLayer.LayerName = Path.GetFileName(aFile); aLayer.FileName = aFile; aLayer.LayerDrawType = LayerDrawType.Map; aLayer.LegendScheme = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Point, Color.Black, 5); aLayer.Visible = true; IsTrue = true; break; case "polyline": aLayer = new VectorLayer(ShapeTypes.Polyline); aLayer.EditAddField(new DataColumn(columnName, typeof(int))); for (i = 0; i < shapeNum; i++) { pNum = Convert.ToInt32(sr.ReadLine()); pList = new List <PointD>(); for (j = 0; j < pNum; j++) { aLine = sr.ReadLine(); dataArray = aLine.Split(','); aPoint = new PointD(); aPoint.X = Convert.ToDouble(dataArray[0]); aPoint.Y = Convert.ToDouble(dataArray[1]); pList.Add(aPoint); } PolylineShape aPLS = new PolylineShape(); aPLS.value = i; aPLS.Extent = MIMath.GetPointsExtent(pList); aPLS.Points = pList; int sNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPLS, sNum)) { aLayer.EditCellValue(columnName, sNum, i); } } aLayer.LayerName = Path.GetFileName(aFile); aLayer.FileName = aFile; aLayer.LayerDrawType = LayerDrawType.Map; aLayer.LegendScheme = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.DarkGray, 1.0F); aLayer.Visible = true; IsTrue = true; break; case "polygon": aLayer = new VectorLayer(ShapeTypes.Polygon); aLayer.EditAddField(new DataColumn(columnName, typeof(int))); ArrayList polygons = new ArrayList(); for (i = 0; i < shapeNum; i++) { pNum = Convert.ToInt32(sr.ReadLine()); pList = new List <PointD>(); for (j = 0; j < pNum; j++) { aLine = sr.ReadLine(); dataArray = aLine.Split(','); aPoint = new PointD(); aPoint.X = Convert.ToDouble(dataArray[0]); aPoint.Y = Convert.ToDouble(dataArray[1]); pList.Add(aPoint); } PolygonShape aPGS = new PolygonShape(); aPGS.lowValue = i; aPGS.highValue = i; aPGS.Extent = MIMath.GetPointsExtent(pList); aPGS.Points = pList; int sNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPGS, sNum)) { aLayer.EditCellValue(columnName, sNum, i); } } aLayer.LayerName = Path.GetFileName(aFile); aLayer.FileName = aFile; aLayer.LayerDrawType = LayerDrawType.Map; aLayer.LegendScheme = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polygon, Color.FromArgb(255, 251, 195), 1.0F); aLayer.Visible = true; IsTrue = true; break; default: MessageBox.Show("Shape type is invalid!" + Environment.NewLine + shapeType, "Error"); IsTrue = false; break; } sr.Close(); if (IsTrue) { return(aLayer); } else { return(null); } }
/// <summary> /// Read station model data /// </summary> /// <param name="timeIdx">Time index</param> /// <param name="levelIdx">Level index</param> /// <returns>Station data</returns> public StationModelData GetStationModelData(int timeIdx, int levelIdx) { StationModelData smData = new StationModelData(); string aStid; int i; Single lon, lat; List <string> dataList = new List <string>(); List <StationModel> smList = new List <StationModel>(); double[,] DiscreteData = new double[10, DataList.Count]; Single minX, maxX, minY, maxY; minX = 0; maxX = 0; minY = 0; maxY = 0; for (i = 0; i < DataList.Count; i++) { dataList = DataList[i]; aStid = (string)dataList[0]; lon = Convert.ToSingle(dataList[1]); lat = Convert.ToSingle(dataList[2]); //if (lon < 0) //{ // lon += 360; //} StationModel sm = new StationModel(); sm.StationIdentifer = aStid; sm.Longitude = lon; sm.Latitude = lat; sm.WindDirection = Convert.ToDouble(dataList[6]); //Wind direction sm.WindSpeed = Convert.ToDouble(dataList[7]); //Wind speed sm.Visibility = Convert.ToDouble(dataList[17]); //Visibility sm.Weather = Convert.ToDouble(dataList[18]); //Weather sm.CloudCover = Convert.ToDouble(dataList[5]); //Cloud cover sm.Temperature = Convert.ToDouble(dataList[19]); //Temperature sm.DewPoint = Convert.ToDouble(dataList[16]); //Dew point //Pressure double press = Convert.ToDouble(dataList[8]); if (MIMath.DoubleEquals(press, this.MissingValue)) { sm.Pressure = press; } else { if (press > 800) { sm.Pressure = press / 10 + 900; } else { sm.Pressure = press / 10 + 1000; } } smList.Add(sm); 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; smData.Data = smList; smData.DataExtent = dataExtent; smData.MissingValue = this.MissingValue; return(smData); }
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 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; }
/// <summary> /// Override PaintOnLayout method /// </summary> /// <param name="g">graphics</param> /// <param name="pageLocation">page location</param> /// <param name="zoom">zoom</param> public override void PaintOnLayout(Graphics g, PointF pageLocation, float zoom) { if (_mapFrame != null) { PointF aP = PageToScreen(this.Left, this.Top, pageLocation, zoom); Rectangle rect = new Rectangle((int)aP.X, (int)aP.Y, (int)(Width * zoom), (int)(Height * zoom)); g.FillRectangle(new SolidBrush(_mapFrame.MapView.BackColor), rect); _mapFrame.MapView.PaintGraphics(g, rect); //Draw lon/lat grid labels if (_mapFrame.DrawGridLabel || _mapFrame.DrawGridTickLine) { List <Extent> extentList = new List <Extent>(); Extent maxExtent = new Extent(); Extent aExtent = new Extent(); SizeF aSF = new SizeF(); SolidBrush aBrush = new SolidBrush(this.ForeColor); Pen aPen = new Pen(_mapFrame.GridLineColor); aPen.Width = _mapFrame.GridLineSize; string drawStr; PointF sP = new PointF(0, 0); PointF eP = new PointF(0, 0); Font font = new Font(_mapFrame.GridFont.Name, _mapFrame.GridFont.Size * zoom, _mapFrame.GridFont.Style); float labX, labY; int len = _mapFrame.TickLineLength; int space = len + _mapFrame.GridLabelShift; if (_mapFrame.InsideTickLine) { space = _mapFrame.GridLabelShift; } for (int i = 0; i < _mapFrame.MapView.GridLabels.Count; i++) { GridLabel aGL = _mapFrame.MapView.GridLabels[i]; switch (_mapFrame.GridLabelPosition) { case GridLabelPosition.LeftBottom: switch (aGL.LabDirection) { case Direction.East: case Direction.North: continue; } break; case GridLabelPosition.LeftUp: switch (aGL.LabDirection) { case Direction.East: case Direction.South: continue; } break; case GridLabelPosition.RightBottom: switch (aGL.LabDirection) { case Direction.Weast: case Direction.North: continue; } break; case GridLabelPosition.RightUp: switch (aGL.LabDirection) { case Direction.Weast: case Direction.South: continue; } break; } labX = (float)aGL.LabPoint.X; labY = (float)aGL.LabPoint.Y; labX = labX + this.Left * zoom + pageLocation.X; labY = labY + this.Top * zoom + pageLocation.Y; sP.X = labX; sP.Y = labY; drawStr = aGL.LabString; if (_mapFrame.DrawDegreeSymbol) { if (drawStr.EndsWith("E") || drawStr.EndsWith("W") || drawStr.EndsWith("N") || drawStr.EndsWith("S")) { drawStr = drawStr.Substring(0, drawStr.Length - 1) + ((char)186).ToString() + drawStr.Substring(drawStr.Length - 1); } else { drawStr = drawStr + ((char)186).ToString(); } } aSF = g.MeasureString(drawStr, font); switch (aGL.LabDirection) { case Direction.South: labX = labX - aSF.Width / 2; labY = labY + space; eP.X = sP.X; if (_mapFrame.InsideTickLine) { eP.Y = sP.Y - len; } else { eP.Y = sP.Y + len; } break; case Direction.Weast: labX = labX - aSF.Width - space; labY = labY - aSF.Height / 2; eP.Y = sP.Y; if (_mapFrame.InsideTickLine) { eP.X = sP.X + len; } else { eP.X = sP.X - len; } break; case Direction.North: labX = labX - aSF.Width / 2; labY = labY - aSF.Height - space; eP.X = sP.X; if (_mapFrame.InsideTickLine) { eP.Y = sP.Y + len; } else { eP.Y = sP.Y - len; } break; case Direction.East: labX = labX + space; labY = labY - aSF.Height / 2; eP.Y = sP.Y; if (_mapFrame.InsideTickLine) { eP.X = sP.X - len; } else { eP.X = sP.X + len; } break; } bool ifDraw = true; float aSize = aSF.Width / 2; float bSize = aSF.Height / 2; aExtent.minX = labX; aExtent.maxX = labX + aSF.Width; aExtent.minY = labY - aSF.Height; aExtent.maxY = labY; //Judge extent if (extentList.Count == 0) { maxExtent = aExtent; extentList.Add(aExtent); } else { if (!MIMath.IsExtentCross(aExtent, maxExtent)) { extentList.Add(aExtent); maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent); } else { for (int j = 0; j < extentList.Count; j++) { if (MIMath.IsExtentCross(aExtent, extentList[j])) { ifDraw = false; break; } } if (ifDraw) { extentList.Add(aExtent); maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent); } } } if (ifDraw) { if (_mapFrame.DrawGridTickLine) { g.DrawLine(aPen, sP, eP); } if (_mapFrame.DrawGridLabel) { g.DrawString(drawStr, font, aBrush, labX, labY); } } } aPen.Dispose(); aBrush.Dispose(); } //Draw neat line if (_mapFrame.DrawNeatLine) { Pen aPen = new Pen(_mapFrame.NeatLineColor, _mapFrame.NeatLineSize); g.DrawRectangle(aPen, rect); aPen.Dispose(); } } }
/// <summary> /// Read Surfer BLN map /// </summary> /// <param name="aFile">file path</param> /// <returns>vector layer</returns> public static VectorLayer ReadMapFile_BLN(string aFile) { StreamReader sr = new StreamReader(aFile); string aLine; string[] dataArray; int i, j, pNum; List <PointD> pList = new List <PointD>(); PointD aPoint; ArrayList dataList = new ArrayList(); bool IsTrue = false; string columnName = "Value"; VectorLayer aLayer = new VectorLayer(ShapeTypes.Polyline); //Read data aLayer.EditAddField(new DataColumn(columnName, typeof(int))); aLine = sr.ReadLine(); bool isComma = true; if (!aLine.Contains(",")) { isComma = false; } i = 0; while (aLine != null) { if (isComma) { pNum = int.Parse(aLine.Split(',')[0]); } else { pNum = int.Parse(MIMath.SplitBySpace(aLine)[0]); } pList = new List <PointD>(); for (j = 0; j < pNum; j++) { aLine = sr.ReadLine(); if (isComma) { dataArray = aLine.Split(','); } else { dataArray = MIMath.SplitBySpace(aLine); } aPoint = new PointD(); aPoint.X = Convert.ToDouble(dataArray[0]); aPoint.Y = Convert.ToDouble(dataArray[1]); pList.Add(aPoint); } PolylineShape aPLS = new PolylineShape(); aPLS.value = i; aPLS.Extent = MIMath.GetPointsExtent(pList); aPLS.Points = pList; i += 1; int sNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPLS, sNum)) { aLayer.EditCellValue(columnName, sNum, i); } aLine = sr.ReadLine(); } aLayer.LayerName = Path.GetFileName(aFile); aLayer.FileName = aFile; aLayer.LayerDrawType = LayerDrawType.Map; aLayer.LegendScheme = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.DarkGray, 1.0F); aLayer.Visible = true; IsTrue = true; sr.Close(); if (IsTrue) { return(aLayer); } else { return(null); } }
/// <summary> /// Override paint method /// </summary> /// <param name="g">graphics</param> public override void Paint(Graphics g) { if (_mapFrame != null) { g.FillRectangle(new SolidBrush(_mapFrame.MapView.BackColor), _mapFrame.LayoutBounds); //Region oldRegion = g.Clip; //GraphicsPath path = new GraphicsPath(); //Rectangle rect = this.Bounds; //path.AddRectangle(rect); //g.SetClip(path); //Matrix oldMatrix = g.Transform; //g.TranslateTransform(this.Left, this.Top); _mapFrame.MapView.PaintGraphics(g, _mapFrame.LayoutBounds); //Draw lon/lat grid labels if (_mapFrame.DrawGridLabel) { List <Extent> extentList = new List <Extent>(); Extent maxExtent = new Extent(); Extent aExtent = new Extent(); SizeF aSF = new SizeF(); SolidBrush aBrush = new SolidBrush(this.ForeColor); Pen aPen = new Pen(_mapFrame.GridLineColor); aPen.Width = _mapFrame.GridLineSize; string drawStr; PointF sP = new PointF(0, 0); PointF eP = new PointF(0, 0); Font font = new Font(_mapFrame.GridFont.Name, _mapFrame.GridFont.Size, _mapFrame.GridFont.Style); float labX, labY; int len = 5; int space = len + 2; for (int i = 0; i < _mapFrame.MapView.GridLabels.Count; i++) { GridLabel aGL = _mapFrame.MapView.GridLabels[i]; switch (_mapFrame.GridLabelPosition) { case GridLabelPosition.LeftBottom: switch (aGL.LabDirection) { case Direction.East: case Direction.North: continue; } break; case GridLabelPosition.LeftUp: switch (aGL.LabDirection) { case Direction.East: case Direction.South: continue; } break; case GridLabelPosition.RightBottom: switch (aGL.LabDirection) { case Direction.Weast: case Direction.North: continue; } break; case GridLabelPosition.RightUp: switch (aGL.LabDirection) { case Direction.Weast: case Direction.South: continue; } break; } labX = (float)aGL.LabPoint.X; labY = (float)aGL.LabPoint.Y; labX = labX + this.Left; labY = labY + this.Top; sP.X = labX; sP.Y = labY; drawStr = aGL.LabString; aSF = g.MeasureString(drawStr, font); switch (aGL.LabDirection) { case Direction.South: labX = labX - aSF.Width / 2; labY = labY + space; eP.X = sP.X; eP.Y = sP.Y + len; break; case Direction.Weast: labX = labX - aSF.Width - space; labY = labY - aSF.Height / 2; eP.X = sP.X - len; eP.Y = sP.Y; break; case Direction.North: labX = labX - aSF.Width / 2; labY = labY - aSF.Height - space; eP.X = sP.X; eP.Y = sP.Y - len; break; case Direction.East: labX = labX + space; labY = labY - aSF.Height / 2; eP.X = sP.X + len; eP.Y = sP.Y; break; } bool ifDraw = true; float aSize = aSF.Width / 2; float bSize = aSF.Height / 2; aExtent.minX = labX; aExtent.maxX = labX + aSF.Width; aExtent.minY = labY - aSF.Height; aExtent.maxY = labY; //Judge extent if (extentList.Count == 0) { maxExtent = aExtent; extentList.Add(aExtent); } else { if (!MIMath.IsExtentCross(aExtent, maxExtent)) { extentList.Add(aExtent); maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent); } else { for (int j = 0; j < extentList.Count; j++) { if (MIMath.IsExtentCross(aExtent, extentList[j])) { ifDraw = false; break; } } if (ifDraw) { extentList.Add(aExtent); maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent); } } } if (ifDraw) { g.DrawLine(aPen, sP, eP); g.DrawString(drawStr, font, aBrush, labX, labY); } } aPen.Dispose(); aBrush.Dispose(); } //g.Transform = oldMatrix; //g.Clip = oldRegion; if (_mapFrame.DrawNeatLine) { Pen aPen = new Pen(_mapFrame.NeatLineColor, _mapFrame.NeatLineSize); g.DrawRectangle(aPen, _mapFrame.LayoutBounds); aPen.Dispose(); } } }
/// <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; }
/// <summary> /// Read GrADS map /// </summary> /// <param name="aFile"></param> /// <returns></returns> public static VectorLayer ReadMapFile_GrADS(string aFile) { FileStream fs = new FileStream(aFile, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); int i, lineNum; byte b; Int16 N, lType; double lon, lat; byte[] bytes; PointD aPoint; List <PointD> pList = new List <PointD>(); VectorLayer aLayer = new VectorLayer(ShapeTypes.Polyline); string columnName = "Value"; DataColumn aDC = new DataColumn(columnName, typeof(int)); aLayer.EditAddField(aDC); lineNum = 0; do { b = br.ReadByte(); // 1-data, 2-skip if (Convert.ToString(b) == "2") { br.ReadBytes(18); continue; } b = br.ReadByte(); // Line type: country, river ... lType = Convert.ToInt16(b); b = br.ReadByte(); // Point number N = Convert.ToInt16(b); for (i = 0; i < N; i++) { bytes = br.ReadBytes(3); //Longitude int val = bytes[0] << 16 | bytes[1] << 8 | bytes[2]; lon = val / 10000.0; bytes = br.ReadBytes(3); //Latitude val = bytes[0] << 16 | bytes[1] << 8 | bytes[2]; lat = val / 10000.0 - 90.0; aPoint = new PointD(); aPoint.X = lon; aPoint.Y = lat; pList.Add(aPoint); } if (pList.Count > 1) { //if (N < 255) //{ PolylineShape aPolyline = new PolylineShape(); aPolyline.value = lineNum; aPolyline.Points = pList; aPolyline.Extent = MIMath.GetPointsExtent(pList); aPolyline.PartNum = 1; aPolyline.parts = new int[1]; aPolyline.parts[0] = 0; int shapeNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPolyline, shapeNum)) { aLayer.EditCellValue(columnName, shapeNum, lineNum); } lineNum++; //} } pList = new List <PointD>(); } while (br.BaseStream.Position < br.BaseStream.Length); br.Close(); fs.Close(); aLayer.LayerName = Path.GetFileName(aFile); aLayer.FileName = aFile; aLayer.LayerDrawType = LayerDrawType.Map; aLayer.LegendScheme = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.DarkGray, 1.0F); aLayer.Visible = true; return(aLayer); }
/// <summary> /// Override operator / for two station data /// </summary> /// <param name="aStData">a station data</param> /// <param name="bStData">a station data</param> /// <returns>result station data</returns> public static StationData operator /(StationData aStData, StationData bStData) { if (!MIMath.IsExtentCross(aStData.DataExtent, bStData.DataExtent)) { return(null); } StationData cStData = new StationData(); List <double[]> cData = new List <double[]>(); string aStid; int stIdx = -1; double minX, maxX, minY, maxY; minX = 0; maxX = 0; minY = 0; maxY = 0; for (int i = 0; i < aStData.Stations.Count; i++) { aStid = aStData.Stations[i]; if (aStid == "99999") { continue; } double aValue = aStData.Data[2, i]; if (aValue == aStData.MissingValue) { //aValue = 0; continue; } stIdx = bStData.Stations.IndexOf(aStid); if (stIdx >= 0) { double bValue = bStData.Data[2, stIdx]; if (bValue == bStData.MissingValue) { //bValue = 0; continue; } cStData.Stations.Add(aStid); double[] theData = new double[3]; theData[0] = aStData.Data[0, i]; theData[1] = aStData.Data[1, i]; theData[2] = aValue / bValue; cData.Add(theData); if (cStData.Stations.Count == 1) { minX = theData[0]; maxX = minX; minY = theData[1]; maxY = minY; } else { if (minX > theData[0]) { minX = theData[0]; } else if (maxX < theData[0]) { maxX = theData[0]; } if (minY > theData[1]) { minY = theData[1]; } else if (maxY < theData[1]) { maxY = theData[1]; } } } } cStData.DataExtent.minX = minX; cStData.DataExtent.maxX = maxX; cStData.DataExtent.minY = minY; cStData.DataExtent.maxY = maxY; cStData.Data = new double[3, cData.Count]; for (int i = 0; i < cData.Count; i++) { cStData.Data[0, i] = cData[i][0]; cStData.Data[1, i] = cData[i][1]; cStData.Data[2, i] = cData[i][2]; } return(cStData); }
/// <summary> /// Read MICAPS map /// </summary> /// <param name="aFile">file name</param> public static VectorLayer ReadMapFile_MICAPS(string aFile) { StreamReader sr = new StreamReader(aFile); string aLine; string[] dataArray; int i, LastNonEmpty, lineNum, pNum; int lType, isClose; List <PointD> pList = new List <PointD>(); //PointD aPoint; ArrayList dataList = new ArrayList(); PolylineShape aPolyline; VectorLayer aLayer = new VectorLayer(ShapeTypes.Polyline); string columnName = "Value"; DataColumn aDC = new DataColumn(columnName, typeof(int)); aLayer.EditAddField(aDC); lineNum = 0; lType = 0; isClose = 0; aLine = sr.ReadLine().Trim(); if (aLine.Substring(0, 7) != "March 9") { MessageBox.Show("Data format is wrong!" + Environment.NewLine + "Need MICAPS (March 9) data!", "Error"); return(null); } aLine = sr.ReadLine(); while (aLine != null) { aLine = sr.ReadLine(); if (aLine == null) { break; } dataArray = aLine.Split(); LastNonEmpty = -1; dataList.Clear(); for (i = 0; i < dataArray.Length; i++) { if (dataArray[i] != string.Empty) { LastNonEmpty++; dataList.Add(dataArray[i]); } } if (dataList.Count != 2) { pNum = Convert.ToInt32(dataList[0]); lType = Convert.ToInt32(dataList[1]); isClose = Convert.ToInt32(dataList[2]); if (pList.Count > 0) { //if (isClose == 1) //{ aPolyline = new PolylineShape(); aPolyline.value = lineNum; aPolyline.Points = pList; aPolyline.Extent = MIMath.GetPointsExtent(pList); aPolyline.PartNum = 1; aPolyline.parts = new int[1]; aPolyline.parts[0] = 0; int shapeNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPolyline, shapeNum)) { aLayer.EditCellValue(columnName, shapeNum, lineNum); } lineNum++; //} pList.Clear(); } } else { PointD aPoint = new PointD(); aPoint.X = Convert.ToDouble(dataList[0]); aPoint.Y = Convert.ToDouble(dataList[1]); pList.Add(aPoint); } } //if (isClose == 1) //{ aPolyline = new PolylineShape(); aPolyline.value = lineNum; aPolyline.Extent = MIMath.GetPointsExtent(pList); aPolyline.Points = pList; int sNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPolyline, sNum)) { aLayer.EditCellValue(columnName, sNum, lineNum); } sr.Close(); aLayer.LayerName = Path.GetFileName(aFile); aLayer.FileName = aFile; aLayer.LayerDrawType = LayerDrawType.Map; aLayer.LegendScheme = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.DarkGray, 1.0F); aLayer.Visible = true; return(aLayer); }