/// <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 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); }
/// <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); }
/// <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> /// 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> /// 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 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 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); }