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); }
/// <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> /// Constructor /// </summary> public ChartSet() { _chartType = ChartTypes.BarChart; _drawCharts = false; _fieldNames = new List <string>(); _xShift = 0; _yShift = 0; _legendScheme = new LegendScheme(ShapeTypes.Polygon); _maxSize = 50; _minSize = 0; _barWidth = 8; _avoidCollision = true; _alignType = AlignType.Center; _view3D = false; _thickness = 5; }
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 Image getImageFromGridData_Bak(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]; for (int i = 0; i < breakNum; i++) { breakValue[i] = Convert.ToDouble(als.LegendBreaks[i].EndValue); breakColor[i] = als.LegendBreaks[i].Color; } Color defaultColor = breakColor[breakNum - 1]; //默认颜色为最后一个颜色 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; //循环只到breakNum-1 是因为最后一个LegendBreaks的EndValue和StartValue是一样的 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 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; } } }
/// <summary> /// Update image by legend scheme /// </summary> /// <param name="als">The legend scheme</param> public void UpdateImage(LegendScheme als) { Image image = getImageFromGridData(_gridData, als); this.Image = image; }
/// <summary> /// Read HYSPLIT trajectory data and create a trajectory point layer /// </summary> /// <returns>vector layer</returns> public VectorLayer CreateTrajPointLayer() { VectorLayer aLayer = new VectorLayer(ShapeTypes.Point); aLayer.EditAddField(new System.Data.DataColumn("TrajID", typeof(int))); aLayer.EditAddField(new System.Data.DataColumn("Date", typeof(string))); aLayer.EditAddField(new System.Data.DataColumn("Lon", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("Lat", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("Height", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("Pressure", typeof(double))); bool isMultiVar = false; if (VarNums[0] > 1) { isMultiVar = true; for (int v = 1; v < VarNums[0]; v++) { aLayer.EditAddField(new System.Data.DataColumn(VarNames[0][v], typeof(double))); } } int TrajNum = 0; for (int t = 0; t < FileNames.Count; t++) { string aFile = FileNames[t]; FileStream fs = new FileStream(aFile, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); string aLine; string[] dataArray; List <string> dataList = new List <string>(); int i, LastNonEmpty; //Record #1 aLine = sr.ReadLine(); //Record #2 for (i = 0; i < MeteoFileNums[t]; i++) { aLine = sr.ReadLine(); } //Record #3 aLine = sr.ReadLine(); //Record #4 for (i = 0; i < TrajeoryNums[t]; i++) { aLine = sr.ReadLine(); } //Record #5 aLine = sr.ReadLine(); //Record #6 int TrajIdx; List <List <object> > pList = new List <List <object> >(); List <List <List <object> > > PointList = new List <List <List <object> > >(); for (i = 0; i < TrajeoryNums[t]; i++) { pList = new List <List <object> >(); PointList.Add(pList); } PointD aPoint = new PointD(); ArrayList polylines = new ArrayList(); DateTime aDate; double Height, Press; while (true) { aLine = sr.ReadLine(); if (aLine == null || aLine == "") { 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]); } } List <object> dList = new List <object>(); TrajIdx = int.Parse(dataList[0]) - 1; aDate = DateTime.Parse(dataList[2] + "-" + dataList[3] + "-" + dataList[4] + " " + dataList[5] + ":00"); aPoint = new PointD(); aPoint.X = double.Parse(dataList[10]); aPoint.Y = double.Parse(dataList[9]); Height = double.Parse(dataList[11]); Press = double.Parse(dataList[12]); dList.Add(aPoint); dList.Add(aDate); dList.Add(Height); dList.Add(Press); if (isMultiVar) { for (i = 13; i < dataList.Count; i++) { dList.Add(double.Parse(dataList[i])); } } PointList[TrajIdx].Add(dList); } for (i = 0; i < TrajeoryNums[t]; i++) { TrajNum += 1; for (int j = 0; j < PointList[i].Count; j++) { PointShape aPS = new PointShape(); aPS.Value = TrajNum; aPS.Point = (PointD)PointList[i][j][0]; int shapeNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPS, shapeNum)) { aLayer.EditCellValue("TrajID", shapeNum, TrajNum); aLayer.EditCellValue("Date", shapeNum, ((DateTime)PointList[i][j][1]).ToString("yyyyMMddHH")); aLayer.EditCellValue("Lat", shapeNum, aPS.Point.Y); aLayer.EditCellValue("Lon", shapeNum, aPS.Point.X); aLayer.EditCellValue("Height", shapeNum, (double)PointList[i][j][2]); aLayer.EditCellValue("Pressure", shapeNum, (double)PointList[i][j][3]); if (isMultiVar) { for (int v = 1; v < VarNums[0]; v++) { aLayer.EditCellValue(VarNames[0][v], shapeNum, (double)PointList[i][j][3 + v]); } } } } } sr.Close(); fs.Close(); } aLayer.LayerName = "Trajectory_Points"; aLayer.LayerDrawType = LayerDrawType.TrajLine; //aLayer.LegendScheme = m_Legend.CreateSingleSymbolLegendScheme(Shape.ShapeType.Polyline, Color.Blue, 1.0F, 1, aDataInfo.TrajeoryNum); aLayer.Visible = true; LegendScheme aLS = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Point, Color.Red, 5.0F); aLS.FieldName = "TrajID"; aLayer.LegendScheme = aLS; return(aLayer); }
/// <summary> /// Set color palette to a image from a palette file /// </summary> /// <param name="aFile">file path</param> public new void SetPalette(string aFile) { base.SetPalette(aFile); _legendScheme = new LegendScheme(ShapeTypes.Image); _legendScheme.ImportFromPaletteFile_Unique(aFile); }
/// <summary> /// Read HYSPLIT trajectory data and create a trajectory start point layer /// </summary> /// <returns>vector layer</returns> public VectorLayer CreateTrajStartPointLayer() { VectorLayer aLayer = new VectorLayer(ShapeTypes.Point); aLayer.EditAddField(new System.Data.DataColumn("TrajID", typeof(int))); aLayer.EditAddField(new System.Data.DataColumn("StartDate", typeof(string))); aLayer.EditAddField(new System.Data.DataColumn("StartLon", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("StartLat", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("StartHeight", typeof(double))); int TrajNum = 0; for (int t = 0; t < FileNames.Count; t++) { string aFile = FileNames[t]; FileStream fs = new FileStream(aFile, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); string aLine; string[] dataArray; List <string> dataList = new List <string>(); int i, LastNonEmpty; //Record #1 aLine = sr.ReadLine(); //Record #2 for (i = 0; i < MeteoFileNums[t]; i++) { aLine = sr.ReadLine(); } //Record #3 aLine = sr.ReadLine(); //Record #4 for (i = 0; i < TrajeoryNums[t]; i++) { aLine = sr.ReadLine(); } //Record #5 aLine = sr.ReadLine(); //Record #6 int TrajIdx; List <object> pList = new List <object>(); List <PointD> PointList = new List <PointD>(); PointD aPoint = new PointD(); for (i = 0; i < TrajeoryNums[t]; i++) { PointList.Add(aPoint); } ArrayList polylines = new ArrayList(); while (true) { aLine = sr.ReadLine(); if (aLine == null || aLine == "") { 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 (float.Parse(dataList[8]) == 0) { TrajIdx = int.Parse(dataList[0]) - 1; aPoint = new PointD(); aPoint.X = double.Parse(dataList[10]); aPoint.Y = double.Parse(dataList[9]); PointList[TrajIdx] = aPoint; } } for (i = 0; i < TrajeoryNums[t]; i++) { PointShape aPS = new PointShape(); TrajNum += 1; aPS.Value = TrajNum; aPS.Point = PointList[i]; int shapeNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPS, shapeNum)) { aLayer.EditCellValue("TrajID", shapeNum, TrajNum); aLayer.EditCellValue("StartDate", shapeNum, TrajInfos[t][i].StartTime.ToString("yyyyMMddHH")); aLayer.EditCellValue("StartLat", shapeNum, TrajInfos[t][i].StartLat); aLayer.EditCellValue("StartLon", shapeNum, TrajInfos[t][i].StartLon); aLayer.EditCellValue("StartHeight", shapeNum, TrajInfos[t][i].StartHeight); } } sr.Close(); fs.Close(); } aLayer.LayerName = "Trajectory_Start_Points"; aLayer.LayerDrawType = LayerDrawType.TrajPoint; aLayer.Visible = true; LegendScheme aLS = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Point, Color.Black, 8.0F); aLS.FieldName = "TrajID"; aLayer.LegendScheme = aLS; return(aLayer); }
/// <summary> /// Read HYSPLIT trajectory data and create a polyline layer /// </summary> /// <returns>vector layer</returns> public VectorLayer CreateTrajLineLayer() { VectorLayer aLayer = new VectorLayer(ShapeTypes.Polyline); aLayer.EditAddField(new System.Data.DataColumn("TrajID", typeof(int))); aLayer.EditAddField(new System.Data.DataColumn("StartDate", typeof(string))); aLayer.EditAddField(new System.Data.DataColumn("StartLon", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("StartLat", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("StartHeight", typeof(double))); int TrajNum = 0; for (int t = 0; t < FileNames.Count; t++) { string aFile = FileNames[t]; FileStream fs = new FileStream(aFile, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); string aLine; string[] dataArray; List <string> dataList = new List <string>(); int i, LastNonEmpty; //Record #1 aLine = sr.ReadLine(); //Record #2 for (i = 0; i < MeteoFileNums[t]; i++) { aLine = sr.ReadLine(); } //Record #3 aLine = sr.ReadLine(); //Record #4 for (i = 0; i < TrajeoryNums[t]; i++) { aLine = sr.ReadLine(); } //Record #5 aLine = sr.ReadLine(); //Record #6 int TrajIdx; List <PointD> pList = new List <PointD>(); List <List <PointD> > PointList = new List <List <PointD> >(); for (i = 0; i < TrajeoryNums[t]; i++) { pList = new List <PointD>(); PointList.Add(pList); } PointD aPoint = new PointD(); ArrayList polylines = new ArrayList(); while (true) { aLine = sr.ReadLine(); if (aLine == null || aLine == "") { 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]); } } TrajIdx = int.Parse(dataList[0]) - 1; aPoint = new PointD(); aPoint.X = double.Parse(dataList[10]); aPoint.Y = double.Parse(dataList[9]); if (PointList[TrajIdx].Count > 1) { PointD oldPoint = PointList[TrajIdx][PointList[TrajIdx].Count - 1]; if (Math.Abs(aPoint.X - oldPoint.X) > 100) { if (aPoint.X > oldPoint.X) { aPoint.X -= 360; } else { aPoint.X += 360; } } } PointList[TrajIdx].Add(aPoint); } for (i = 0; i < TrajeoryNums[t]; i++) { Shape.PolylineShape aPolyline = new Shape.PolylineShape(); //aPolyline.value = aDataInfo.TrajInfos[i].StartTime.ToBinary(); TrajNum += 1; aPolyline.value = TrajNum; aPolyline.Points = PointList[i]; aPolyline.Extent = MIMath.GetPointsExtent(aPolyline.Points); int shapeNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPolyline, shapeNum)) { aLayer.EditCellValue("TrajID", shapeNum, TrajNum); aLayer.EditCellValue("StartDate", shapeNum, TrajInfos[t][i].StartTime.ToString("yyyyMMddHH")); aLayer.EditCellValue("StartLat", shapeNum, TrajInfos[t][i].StartLat); aLayer.EditCellValue("StartLon", shapeNum, TrajInfos[t][i].StartLon); aLayer.EditCellValue("StartHeight", shapeNum, TrajInfos[t][i].StartHeight); } } sr.Close(); fs.Close(); } aLayer.LayerName = "Trajectory_Lines"; aLayer.LayerDrawType = LayerDrawType.TrajLine; //aLayer.LegendScheme = m_Legend.CreateSingleSymbolLegendScheme(Shape.ShapeType.Polyline, Color.Blue, 1.0F, 1, aDataInfo.TrajeoryNum); aLayer.Visible = true; LegendScheme aLS = LegendManage.CreateUniqValueLegendScheme(aLayer, 1, TrajeoryNumber); aLS.FieldName = "TrajID"; aLayer.LegendScheme = aLS; return(aLayer); }
/// <summary> /// Read MICAPS 7 data and create a trajectory point layer /// </summary> /// <returns>vector layer</returns> public VectorLayer CreateTrajPointLayer() { VectorLayer aLayer = new VectorLayer(ShapeTypes.Point); aLayer.EditAddField(new System.Data.DataColumn("TrajID", typeof(int))); aLayer.EditAddField(new System.Data.DataColumn("Date", typeof(string))); aLayer.EditAddField(new System.Data.DataColumn("PreHour", typeof(int))); aLayer.EditAddField(new System.Data.DataColumn("Lon", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("Lat", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("WindSpeed", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("Radius_W7", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("Radius_W10", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("MoveDir", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("MoveSpeed", typeof(double))); int TrajNum = 0; for (int t = 0; t < FileNames.Count; t++) { string aFile = FileNames[t]; FileStream fs = new FileStream(aFile, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); string aLine; string[] dataArray; List <string> dataList = new List <string>(); int i, LastNonEmpty; // int TrajIdx = -1; List <List <object> > pList = new List <List <object> >(); List <List <List <object> > > PointList = new List <List <List <object> > >(); for (i = 0; i < TrajeoryNums[t]; i++) { pList = new List <List <object> >(); PointList.Add(pList); } PointD aPoint = new PointD(); ArrayList polylines = new ArrayList(); DateTime aDate; aLine = sr.ReadLine(); aLine = sr.ReadLine(); while (aLine != null) { if (aLine.Trim() == String.Empty) { aLine = sr.ReadLine(); continue; } dataArray = aLine.Split(); LastNonEmpty = -1; dataList.Clear(); for (i = 0; i < dataArray.Length; i++) { if (dataArray[i] != string.Empty) { LastNonEmpty++; dataList.Add(dataArray[i]); } } switch (dataList.Count) { case 4: TrajIdx += 1; break; case 13: List <object> dList = new List <object>(); aDate = DateTime.Parse(dataList[0] + "-" + dataList[1] + "-" + dataList[2] + " " + dataList[3] + ":00"); aPoint = new PointD(); aPoint.X = double.Parse(dataList[5]); aPoint.Y = double.Parse(dataList[6]); dList.Add(aPoint); dList.Add(aDate); dList.Add(int.Parse(dataList[4])); for (int d = 0; d < 5; d++) { dList.Add(double.Parse(dataList[d + 7])); } PointList[TrajIdx].Add(dList); break; } aLine = sr.ReadLine(); } for (i = 0; i < TrajeoryNums[t]; i++) { TrajNum += 1; for (int j = 0; j < PointList[i].Count; j++) { PointShape aPS = new PointShape(); aPS.Value = TrajNum; aPS.Point = (PointD)PointList[i][j][0]; int shapeNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPS, shapeNum)) { aLayer.EditCellValue("TrajID", shapeNum, TrajNum); aLayer.EditCellValue("Date", shapeNum, ((DateTime)PointList[i][j][1]).ToString("yyyyMMddHH")); aLayer.EditCellValue("PreHour", shapeNum, (int)PointList[i][j][2]); aLayer.EditCellValue("Lat", shapeNum, aPS.Point.Y); aLayer.EditCellValue("Lon", shapeNum, aPS.Point.X); aLayer.EditCellValue("WindSpeed", shapeNum, (double)PointList[i][j][3]); aLayer.EditCellValue("Radius_W7", shapeNum, (double)PointList[i][j][4]); aLayer.EditCellValue("Radius_W10", shapeNum, (double)PointList[i][j][5]); aLayer.EditCellValue("MoveDir", shapeNum, (double)PointList[i][j][6]); aLayer.EditCellValue("MoveSpeed", shapeNum, (double)PointList[i][j][7]); } } } sr.Close(); fs.Close(); } aLayer.LayerName = "Typhoon_Points"; aLayer.LayerDrawType = LayerDrawType.TrajLine; //aLayer.LegendScheme = m_Legend.CreateSingleSymbolLegendScheme(Shape.ShapeType.Polyline, Color.Blue, 1.0F, 1, aDataInfo.TrajeoryNum); aLayer.Visible = true; LegendScheme aLS = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Point, Color.Red, 5.0F); aLS.FieldName = "TrajID"; aLayer.LegendScheme = aLS; return(aLayer); }
/// <summary> /// Read MICAPS 7 data and create a trajectory start point layer /// </summary> /// <returns>vector layer</returns> public VectorLayer CreateTrajStartPointLayer() { VectorLayer aLayer = new VectorLayer(ShapeTypes.Point); aLayer.EditAddField(new System.Data.DataColumn("TrajID", typeof(int))); aLayer.EditAddField(new System.Data.DataColumn("StartDate", typeof(string))); aLayer.EditAddField(new System.Data.DataColumn("StartLon", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("StartLat", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("StartHeight", typeof(double))); int TrajNum = 0; for (int t = 0; t < FileNames.Count; t++) { string aFile = FileNames[t]; FileStream fs = new FileStream(aFile, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); string aLine; string[] dataArray; List <string> dataList = new List <string>(); int i, LastNonEmpty; // int TrajIdx = -1; List <object> pList = new List <object>(); List <PointD> PointList = new List <PointD>(); PointD aPoint = new PointD(); for (i = 0; i < TrajeoryNums[t]; i++) { PointList.Add(aPoint); } ArrayList polylines = new ArrayList(); aLine = sr.ReadLine(); aLine = sr.ReadLine(); bool IsFirstTraj = false; while (aLine != null) { if (aLine.Trim() == String.Empty) { aLine = sr.ReadLine(); continue; } dataArray = aLine.Split(); LastNonEmpty = -1; dataList.Clear(); for (i = 0; i < dataArray.Length; i++) { if (dataArray[i] != string.Empty) { LastNonEmpty++; dataList.Add(dataArray[i]); } } switch (dataList.Count) { case 4: TrajIdx += 1; IsFirstTraj = true; break; case 13: if (IsFirstTraj) { aPoint = new PointD(); aPoint.X = double.Parse(dataList[5]); aPoint.Y = double.Parse(dataList[6]); PointList[TrajIdx] = aPoint; IsFirstTraj = false; } break; } aLine = sr.ReadLine(); } for (i = 0; i < TrajeoryNums[t]; i++) { PointShape aPS = new PointShape(); TrajNum += 1; aPS.Value = TrajNum; aPS.Point = PointList[i]; int shapeNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPS, shapeNum)) { aLayer.EditCellValue("TrajID", shapeNum, TrajNum); aLayer.EditCellValue("StartDate", shapeNum, TrajInfos[t][i].StartTime.ToString("yyyyMMddHH")); aLayer.EditCellValue("StartLat", shapeNum, TrajInfos[t][i].StartLat); aLayer.EditCellValue("StartLon", shapeNum, TrajInfos[t][i].StartLon); aLayer.EditCellValue("StartHeight", shapeNum, TrajInfos[t][i].StartHeight); } } sr.Close(); fs.Close(); } aLayer.LayerName = "Typhoon_Start_Points"; aLayer.LayerDrawType = LayerDrawType.TrajPoint; aLayer.Visible = true; LegendScheme aLS = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Point, Color.Black, 8.0F); aLS.FieldName = "TrajID"; aLayer.LegendScheme = aLS; return(aLayer); }
/// <summary> /// Read MICAPS 7 data and create a polyline layer /// </summary> /// <returns>vector layer</returns> public VectorLayer CreateTrajLineLayer() { VectorLayer aLayer = new VectorLayer(ShapeTypes.Polyline); aLayer.EditAddField(new System.Data.DataColumn("TrajIndex", typeof(int))); aLayer.EditAddField(new System.Data.DataColumn("TrajName", typeof(string))); aLayer.EditAddField(new System.Data.DataColumn("TrajID", typeof(string))); aLayer.EditAddField(new System.Data.DataColumn("TrajCenter", typeof(string))); aLayer.EditAddField(new System.Data.DataColumn("StartDate", typeof(string))); aLayer.EditAddField(new System.Data.DataColumn("StartLon", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("StartLat", typeof(double))); aLayer.EditAddField(new System.Data.DataColumn("StartHeight", typeof(double))); int TrajNum = 0; for (int t = 0; t < FileNames.Count; t++) { string aFile = FileNames[t]; FileStream fs = new FileStream(aFile, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); string aLine; string[] dataArray; List <string> dataList = new List <string>(); int i, LastNonEmpty; int TrajIdx = -1; List <PointD> pList = new List <PointD>(); List <List <PointD> > PointList = new List <List <PointD> >(); for (i = 0; i < TrajeoryNums[t]; i++) { pList = new List <PointD>(); PointList.Add(pList); } PointD aPoint = new PointD(); ArrayList polylines = new ArrayList(); aLine = sr.ReadLine(); aLine = sr.ReadLine(); while (aLine != null) { if (aLine.Trim() == String.Empty) { aLine = sr.ReadLine(); continue; } dataArray = aLine.Split(); LastNonEmpty = -1; dataList.Clear(); for (i = 0; i < dataArray.Length; i++) { if (dataArray[i] != string.Empty) { LastNonEmpty++; dataList.Add(dataArray[i]); } } switch (dataList.Count) { case 4: TrajIdx += 1; break; case 13: aPoint = new PointD(); aPoint.X = double.Parse(dataList[5]); aPoint.Y = double.Parse(dataList[6]); PointList[TrajIdx].Add(aPoint); break; } aLine = sr.ReadLine(); } for (i = 0; i < TrajeoryNums[t]; i++) { Shape.PolylineShape aPolyline = new Shape.PolylineShape(); //aPolyline.value = aDataInfo.TrajInfos[i].StartTime.ToBinary(); TrajNum += 1; aPolyline.value = TrajNum; aPolyline.Points = PointList[i]; aPolyline.Extent = MIMath.GetPointsExtent(aPolyline.Points); int shapeNum = aLayer.ShapeNum; if (aLayer.EditInsertShape(aPolyline, shapeNum)) { aLayer.EditCellValue("TrajIndex", shapeNum, TrajNum); aLayer.EditCellValue("TrajName", shapeNum, TrajInfos[t][i].TrajName); aLayer.EditCellValue("TrajID", shapeNum, TrajInfos[t][i].TrajID); aLayer.EditCellValue("TrajCenter", shapeNum, TrajInfos[t][i].TrajCenter); aLayer.EditCellValue("StartDate", shapeNum, TrajInfos[t][i].StartTime.ToString("yyyyMMddHH")); aLayer.EditCellValue("StartLat", shapeNum, TrajInfos[t][i].StartLat); aLayer.EditCellValue("StartLon", shapeNum, TrajInfos[t][i].StartLon); aLayer.EditCellValue("StartHeight", shapeNum, TrajInfos[t][i].StartHeight); } } sr.Close(); fs.Close(); } aLayer.LayerName = "Typhoon_Lines"; aLayer.LayerDrawType = LayerDrawType.TrajLine; //aLayer.LegendScheme = m_Legend.CreateSingleSymbolLegendScheme(Shape.ShapeType.Polyline, Color.Blue, 1.0F, 1, aDataInfo.TrajeoryNum); aLayer.Visible = true; LegendScheme aLS = LegendManage.CreateUniqValueLegendScheme(aLayer, 1, TrajeoryNumber); aLS.FieldName = "TrajIndex"; aLayer.LegendScheme = aLS; return(aLayer); }