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