Example #1
0
        /// <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);
        }
        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);
        }
Example #4
0
        /// <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 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);
        }
Example #6
0
        /// <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>
        /// 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);
        }
        /// <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);
        }