/// <summary>
        /// Create legend scheme from grid data
        /// </summary>
        /// <param name="aGridData">GridData</param>
        /// <param name="aLT">legend type</param>
        /// <param name="aST">shape type</param>
        /// <param name="hasNoData">ref if has undefine data</param>
        /// <returns>legend scheme</returns>
        public static LegendScheme CreateLegendSchemeFromGridData(GridData aGridData,
                                                                  LegendType aLT, ShapeTypes aST, ref Boolean hasNoData)
        {
            LegendScheme aLS = new LegendScheme(aST);

            double[] CValues;
            Color[]  colors;
            double   MinData = 0;
            double   MaxData = 0;

            hasNoData = ContourDraw.GetMaxMinValue(aGridData.Data, aGridData.MissingValue, ref MinData, ref MaxData);
            CValues   = CreateContourValues(MinData, MaxData);
            colors    = CreateRainBowColors(CValues.Length + 1);

            //Generate lengendscheme
            if (aLT == LegendType.UniqueValue)
            {
                aLS = CreateUniqValueLegendScheme(CValues, colors,
                                                  aST, MinData, MaxData, hasNoData, aGridData.MissingValue);
            }
            else
            {
                aLS = CreateGraduatedLegendScheme(CValues, colors,
                                                  aST, MinData, MaxData, hasNoData, aGridData.MissingValue);
            }

            return(aLS);
        }
Exemple #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ChartBreak(ChartTypes chartType) : base()
 {
     BreakType     = BreakTypes.ChartBreak;
     _chartType    = chartType;
     _chartData    = new List <float>();
     _xShift       = 0;
     _yShift       = 0;
     _legendScheme = new LegendScheme(ShapeTypes.Polygon);
     _maxSize      = 50;
     _minSize      = 10;
     _barWidth     = 10;
     _alignType    = AlignType.Center;
     _view3D       = false;
     _thickness    = 5;
     _shpIdx       = 0;
 }
Exemple #3
0
        /// <summary>
        /// Update legendscheme
        /// </summary>
        /// <param name="mapLayer">map layer</param>
        /// <param name="aLS">legend scheme</param>
        public void Update(MapLayer mapLayer, LegendScheme aLS)
        {
            //_IsLoading = true;
            _mapLayer = mapLayer;

            SetLegendScheme(aLS);

            switch (mapLayer.LayerType)
            {
            case LayerTypes.VectorLayer:
                //Set legend type
                CB_LegendType.Items.Clear();
                CB_LegendType.Items.Add(Enum.GetName(typeof(LegendType), LegendType.SingleSymbol));
                CB_LegendType.Items.Add(Enum.GetName(typeof(LegendType), LegendType.UniqueValue));
                CB_LegendType.Items.Add(Enum.GetName(typeof(LegendType), LegendType.GraduatedColor));
                CB_LegendType.Text = Enum.GetName(typeof(LegendType), _legendScheme.LegendType);
                if (CB_LegendType.Text == Enum.GetName(typeof(LegendType), LegendType.SingleSymbol))
                {
                    TSB_Add.Enabled        = false;
                    TSB_Del.Enabled        = false;
                    TSB_DelAll.Enabled     = false;
                    TSB_Down.Enabled       = false;
                    TSB_Up.Enabled         = false;
                    TSB_MakeBreaks.Enabled = false;
                }

                //Set field text
                CB_Field.Text = _legendScheme.FieldName;

                if (m_IfFrmMeteoData)
                {
                    CB_LegendType.Enabled = false;
                    CB_Field.Enabled      = false;
                }
                break;

            default:
                CB_LegendType.Enabled = false;
                CB_Field.Enabled      = false;
                break;
            }

            //_IsLoading = false;
            _ifCreateLegendScheme = true;
            this.Refresh();
        }
        /// <summary>
        /// Clone legend scheme
        /// </summary>
        /// <returns>legend scheme</returns>
        public object Clone()
        {
            LegendScheme bLS = new LegendScheme(ShapeType);

            bLS.FieldName = FieldName;
            //bLS.breakNum = breakNum;
            bLS.HasNoData    = HasNoData;
            bLS.LegendType   = LegendType;
            bLS.MinValue     = MinValue;
            bLS.MaxValue     = MaxValue;
            bLS.MissingValue = MissingValue;
            foreach (ColorBreak aCB in LegendBreaks)
            {
                bLS.LegendBreaks.Add((ColorBreak)aCB.Clone());
            }

            return(bLS);
        }
Exemple #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        public LegendView()
        {
            InitializeComponent();

            this.SetStyle(
                ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.OptimizedDoubleBuffer, true);
            this.BackColor    = Color.White;
            TB_Editor.Visible = false;

            _frmPointSymbolSet    = new frmPointSymbolSet(this);
            _frmPolylineSymbolSet = new frmPolylineSymbolSet(this);
            _frmPolygonSymbolSet  = new frmPolygonSymbolSet(this);
            _frmColorSymbolSet    = new frmColorSymbolSet(this);
            _legendScheme         = null;
            _breakHeight          = 20;
            _symbolWidth          = 60;
            _valueWidth           = (this.Width - _symbolWidth) / 2;
            _labelWidth           = _valueWidth;
        }
Exemple #6
0
        /// <summary>
        /// Update legend nodes using a legend scheme
        /// </summary>
        /// <param name="aLS">legend scheme</param>
        public void UpdateLegendScheme(LegendScheme aLS)
        {
            if (_mapLayer.LayerType != LayerTypes.ImageLayer)
            {
                _legendNodes.Clear();
                LegendNode aTN = new LegendNode();
                for (int i = 0; i < aLS.BreakNum; i++)
                {
                    if (aLS.LegendBreaks[i].DrawShape)
                    {
                        aTN             = new LegendNode();
                        aTN.ShapeType   = ShapeType;
                        aTN.LegendBreak = aLS.LegendBreaks[i];
                        _legendNodes.Add(aTN);
                    }
                }

                if (_mapLayer.LayerType == LayerTypes.VectorLayer)
                {
                    VectorLayer aLayer = (VectorLayer)_mapLayer;
                    if (aLayer.ChartSet.DrawCharts && aLayer.ChartPoints.Count > 0)
                    {
                        LegendNode aLN = new LegendNode();
                        aLN.ShapeType = ShapeTypes.Polygon;
                        ChartBreak aCB = ((ChartBreak)aLayer.ChartPoints[0].Legend).GetSampleChartBreak();
                        aLN.LegendBreak = aCB;
                        aLN.Height      = ((ChartBreak)aLN.LegendBreak).GetHeight() + 10;
                        _legendNodes.Add(aLN);
                        for (int i = 0; i < aLayer.ChartSet.LegendScheme.BreakNum; i++)
                        {
                            aLN             = new LegendNode();
                            aLN.ShapeType   = ShapeTypes.Polygon;
                            aLN.LegendBreak = aLayer.ChartSet.LegendScheme.LegendBreaks[i];
                            _legendNodes.Add(aLN);
                        }
                    }
                }
            }
        }
Exemple #7
0
 /// <summary>
 /// Update legend scheme
 /// </summary>
 /// <param name="aLS">legend scheme</param>
 public void Update(LegendScheme aLS)
 {
     _legendScheme = aLS;
     this.Invalidate();
 }
        /// <summary>
        /// Set contour values and colors
        /// </summary>
        /// <param name="aLS"></param>
        /// <param name="cValues"></param>
        /// <param name="colors"></param>
        public static void SetContoursAndColors(LegendScheme aLS, ref double[] cValues, ref Color[] colors)
        {
            int i;

            if (aLS.HasNoData)
            {
                cValues = new double[aLS.BreakNum - 2];
                colors  = new Color[aLS.BreakNum - 1];
            }
            else
            {
                cValues = new double[aLS.BreakNum - 1];
                colors  = new Color[aLS.BreakNum];
            }
            switch (aLS.ShapeType)
            {
            case ShapeTypes.Polygon:
                for (i = 0; i < aLS.BreakNum; i++)
                {
                    PolygonBreak aPGB = (PolygonBreak)aLS.LegendBreaks[i];
                    colors[i] = aPGB.Color;
                    if (i > 0)
                    {
                        cValues[i - 1] = double.Parse(aPGB.StartValue.ToString());
                    }
                }
                break;

            case ShapeTypes.Polyline:
                if (aLS.LegendType == LegendType.UniqueValue)
                {
                    cValues   = new double[aLS.BreakNum];
                    colors    = new Color[aLS.BreakNum + 1];
                    colors[0] = Color.White;
                    for (i = 0; i < aLS.BreakNum; i++)
                    {
                        PolyLineBreak aPLB = (PolyLineBreak)aLS.LegendBreaks[i];
                        colors[i + 1] = aPLB.Color;
                        cValues[i]    = double.Parse(aPLB.StartValue.ToString());
                    }
                }
                else
                {
                    for (i = 0; i < aLS.BreakNum; i++)
                    {
                        PolyLineBreak aPLB = (PolyLineBreak)aLS.LegendBreaks[i];
                        colors[i] = aPLB.Color;
                        if (i > 0)
                        {
                            cValues[i - 1] = double.Parse(aPLB.StartValue.ToString());
                        }
                    }
                }
                break;

            case ShapeTypes.Point:
                for (i = 0; i < aLS.BreakNum; i++)
                {
                    PointBreak aPB = (PointBreak)aLS.LegendBreaks[i];
                    if (!aPB.IsNoData)
                    {
                        colors[i] = aPB.Color;
                        if (i > 0)
                        {
                            cValues[i - 1] = double.Parse(aPB.StartValue.ToString());
                        }
                    }
                }
                break;
            }
        }
        /// <summary>
        /// Create Graduated color legend scheme
        /// </summary>
        /// <param name="CValues"></param>
        /// <param name="colors"></param>
        /// <param name="aST"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="hasNodata"></param>
        /// <param name="unDef"></param>
        /// <returns></returns>
        public static LegendScheme CreateGraduatedLegendScheme(double[] CValues, Color[] colors, ShapeTypes aST,
                                                               double min, double max, Boolean hasNodata, double unDef)
        {
            LegendScheme legendScheme = new LegendScheme(aST);

            legendScheme.LegendType   = LegendType.GraduatedColor;
            legendScheme.ShapeType    = aST;
            legendScheme.LegendBreaks = new List <ColorBreak>();
            legendScheme.MinValue     = min;
            legendScheme.MaxValue     = max;
            legendScheme.MissingValue = unDef;
            int i;

            switch (aST)
            {
            case ShapeTypes.Point:
                for (i = 0; i < colors.Length; i++)
                {
                    PointBreak aPB = new PointBreak();
                    aPB.Color        = colors[i];
                    aPB.OutlineColor = Color.Black;
                    aPB.IsNoData     = false;
                    aPB.DrawOutline  = true;
                    aPB.DrawFill     = true;
                    aPB.DrawShape    = true;
                    if (i == 0)
                    {
                        aPB.StartValue = min;
                    }
                    else
                    {
                        aPB.StartValue = CValues[i - 1];
                    }
                    if (i == colors.Length - 1)
                    {
                        aPB.EndValue = max;
                    }
                    else
                    {
                        aPB.EndValue = CValues[i];
                    }
                    aPB.Size  = (Single)i / 2 + 2;
                    aPB.Style = PointStyle.Circle;
                    if (aPB.StartValue == aPB.EndValue)
                    {
                        aPB.Caption = aPB.StartValue.ToString();
                    }
                    else
                    {
                        if (i == 0)
                        {
                            aPB.Caption = "< " + aPB.EndValue.ToString();
                        }
                        else if (i == colors.Length - 1)
                        {
                            aPB.Caption = "> " + aPB.StartValue.ToString();
                        }
                        else
                        {
                            aPB.Caption = aPB.StartValue.ToString() + " - " + aPB.EndValue.ToString();
                        }
                    }

                    legendScheme.LegendBreaks.Add(aPB);
                }
                legendScheme.HasNoData = false;
                if (hasNodata)
                {
                    PointBreak aPB = new PointBreak();
                    aPB.Color        = Color.Gray;
                    aPB.OutlineColor = Color.Black;
                    aPB.StartValue   = unDef;
                    aPB.EndValue     = aPB.StartValue;
                    aPB.Size         = 1;
                    aPB.Style        = PointStyle.Circle;
                    aPB.Caption      = "NoData";
                    aPB.IsNoData     = true;
                    aPB.DrawShape    = true;
                    aPB.DrawOutline  = true;
                    legendScheme.LegendBreaks.Add(aPB);
                    legendScheme.HasNoData = true;
                }
                break;

            case ShapeTypes.Polyline:
            case ShapeTypes.PolylineZ:
                for (i = 0; i < colors.Length; i++)
                {
                    PolyLineBreak aPLB = new PolyLineBreak();
                    aPLB.Color        = colors[i];
                    aPLB.Size         = 1.0F;
                    aPLB.Style        = LineStyles.Solid;
                    aPLB.DrawPolyline = true;
                    if (i == 0)
                    {
                        aPLB.StartValue = min;
                    }
                    else
                    {
                        aPLB.StartValue = CValues[i - 1];
                    }
                    if (i == colors.Length - 1)
                    {
                        aPLB.EndValue = max;
                    }
                    else
                    {
                        aPLB.EndValue = CValues[i];
                    }
                    if (aPLB.StartValue == aPLB.EndValue)
                    {
                        aPLB.Caption = aPLB.StartValue.ToString();
                    }
                    else
                    {
                        if (i == 0)
                        {
                            aPLB.Caption = "< " + aPLB.EndValue.ToString();
                        }
                        else if (i == colors.Length - 1)
                        {
                            aPLB.Caption = "> " + aPLB.StartValue.ToString();
                        }
                        else
                        {
                            aPLB.Caption = aPLB.StartValue.ToString() + " - " + aPLB.EndValue.ToString();
                        }
                    }
                    aPLB.SymbolColor = aPLB.Color;
                    if (Enum.IsDefined(typeof(PointStyle), i))
                    {
                        aPLB.SymbolStyle = (PointStyle)i;
                    }

                    legendScheme.LegendBreaks.Add(aPLB);
                }
                legendScheme.HasNoData = false;
                break;

            case ShapeTypes.Polygon:
                for (i = 0; i < colors.Length; i++)
                {
                    PolygonBreak aPGB = new PolygonBreak();
                    aPGB.Color        = colors[i];
                    aPGB.OutlineColor = Color.Gray;
                    aPGB.OutlineSize  = 1.0F;
                    aPGB.DrawFill     = true;
                    aPGB.DrawOutline  = false;
                    aPGB.DrawShape    = true;
                    if (i == 0)
                    {
                        aPGB.StartValue = min;
                    }
                    else
                    {
                        aPGB.StartValue = CValues[i - 1];
                    }
                    if (i == colors.Length - 1)
                    {
                        aPGB.EndValue = max;
                    }
                    else
                    {
                        aPGB.EndValue = CValues[i];
                    }
                    if (aPGB.StartValue == aPGB.EndValue)
                    {
                        aPGB.Caption = aPGB.StartValue.ToString();
                    }
                    else
                    {
                        if (i == 0)
                        {
                            aPGB.Caption = "< " + aPGB.EndValue.ToString();
                        }
                        else if (i == colors.Length - 1)
                        {
                            aPGB.Caption = "> " + aPGB.StartValue.ToString();
                        }
                        else
                        {
                            aPGB.Caption = aPGB.StartValue.ToString() + " - " + aPGB.EndValue.ToString();
                        }
                    }
                    if (Enum.IsDefined(typeof(HatchStyle), i))
                    {
                        aPGB.Style = (HatchStyle)i;
                    }

                    legendScheme.LegendBreaks.Add(aPGB);
                }
                legendScheme.HasNoData = false;
                break;

            case ShapeTypes.Image:
                for (i = 0; i < colors.Length; i++)
                {
                    ColorBreak aCB = new ColorBreak();
                    aCB.Color = colors[i];
                    if (i == 0)
                    {
                        aCB.StartValue = min;
                    }
                    else
                    {
                        aCB.StartValue = CValues[i - 1];
                    }
                    if (i == colors.Length - 1)
                    {
                        aCB.EndValue = max;
                    }
                    else
                    {
                        aCB.EndValue = CValues[i];
                    }
                    if (aCB.StartValue == aCB.EndValue)
                    {
                        aCB.Caption = aCB.StartValue.ToString();
                    }
                    else
                    {
                        if (i == 0)
                        {
                            aCB.Caption = "< " + aCB.EndValue.ToString();
                        }
                        else if (i == colors.Length - 1)
                        {
                            aCB.Caption = "> " + aCB.StartValue.ToString();
                        }
                        else
                        {
                            aCB.Caption = aCB.StartValue.ToString() + " - " + aCB.EndValue.ToString();
                        }
                    }

                    legendScheme.LegendBreaks.Add(aCB);
                }
                legendScheme.HasNoData = false;
                if (hasNodata)
                {
                    ColorBreak aCB = new ColorBreak();
                    aCB.Color      = Color.Gray;
                    aCB.StartValue = unDef;
                    aCB.EndValue   = aCB.StartValue;
                    aCB.Caption    = "NoData";
                    aCB.IsNoData   = true;
                    legendScheme.LegendBreaks.Add(aCB);
                    legendScheme.HasNoData = true;
                }
                break;
            }
            //legendScheme.breakNum = legendScheme.LegendBreaks.Count;

            return(legendScheme);
        }
        /// <summary>
        /// Create unique value legend scheme from layer
        /// </summary>
        /// <param name="aLayer"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public static LegendScheme CreateUniqValueLegendScheme(VectorLayer aLayer, double min, double max)
        {
            LegendScheme aLS = new LegendScheme(aLayer.ShapeType);

            double[]  CValues;
            Color[]   colors;
            ArrayList valueList = new ArrayList();

            switch (aLayer.ShapeType)
            {
            case ShapeTypes.Point:
                foreach (PointShape aPS in aLayer.ShapeList)
                {
                    if (!valueList.Contains(aPS.Value))
                    {
                        valueList.Add(aPS.Value);
                    }
                }
                break;

            case ShapeTypes.Polyline:
            case ShapeTypes.PolylineZ:
                foreach (PolylineShape aPLS in aLayer.ShapeList)
                {
                    if (!valueList.Contains(aPLS.value))
                    {
                        valueList.Add(aPLS.value);
                    }
                }
                break;

            default:
                foreach (PolygonShape aPGS in aLayer.ShapeList)
                {
                    if (!valueList.Contains(aPGS.lowValue))
                    {
                        valueList.Add(aPGS.lowValue);
                    }
                }
                break;
            }

            CValues = (double[])valueList.ToArray(typeof(double));
            if (CValues.Length <= 13)
            {
                colors = CreateRainBowColors(CValues.Length);
            }
            else
            {
                colors = CreateRandomColors(CValues.Length);
            }
            List <Color> CList = new List <Color>(colors);

            CList.Insert(0, Color.White);
            colors = CList.ToArray();

            aLS = CreateUniqValueLegendScheme(CValues, colors,
                                              aLayer.ShapeType, min, max, false, -9999);

            return(aLS);
        }
        /// <summary>
        /// Create unique value legend scheme
        /// </summary>
        /// <param name="CValues"></param>
        /// <param name="captions"></param>
        /// <param name="colors"></param>
        /// <param name="aST"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="hasNodata"></param>
        /// <param name="unDef"></param>
        /// <returns></returns>
        public static LegendScheme CreateUniqValueLegendScheme(List <string> CValues, List <string> captions, Color[] colors, ShapeTypes aST,
                                                               double min, double max, Boolean hasNodata, double unDef)
        {
            LegendScheme legendScheme = new LegendScheme(aST);

            legendScheme.LegendType   = LegendType.UniqueValue;
            legendScheme.ShapeType    = aST;
            legendScheme.LegendBreaks = new List <ColorBreak>();
            legendScheme.MinValue     = min;
            legendScheme.MaxValue     = max;
            legendScheme.MissingValue = unDef;
            int        i;
            List <int> idxList = new List <int>();

            switch (aST)
            {
            case ShapeTypes.Point:
            case ShapeTypes.PointZ:
                for (i = 1; i < colors.Length; i++)
                {
                    PointBreak aPB = new PointBreak();
                    aPB.Color      = colors[i];
                    aPB.StartValue = CValues[i - 1];
                    aPB.EndValue   = aPB.StartValue;
                    if (colors.Length <= 13)
                    {
                        aPB.Size = (Single)i / 2 + 2;
                    }
                    else
                    {
                        aPB.Size = 5;
                    }
                    aPB.Style        = PointStyle.Circle;
                    aPB.OutlineColor = Color.Black;
                    aPB.IsNoData     = false;
                    aPB.DrawOutline  = true;
                    aPB.DrawFill     = true;
                    aPB.DrawShape    = true;
                    aPB.Caption      = captions[i - 1];

                    legendScheme.LegendBreaks.Add(aPB);
                }
                legendScheme.HasNoData = false;
                break;

            case ShapeTypes.Polyline:
            case ShapeTypes.PolylineZ:
                idxList = GetEnumList(colors.Length, typeof(PointStyle));
                for (i = 1; i < colors.Length; i++)
                {
                    PolyLineBreak aPLB = new PolyLineBreak();
                    aPLB.Color        = colors[i];
                    aPLB.StartValue   = CValues[i - 1];
                    aPLB.EndValue     = aPLB.StartValue;
                    aPLB.Size         = 1.0F;
                    aPLB.Style        = LineStyles.Solid;
                    aPLB.DrawPolyline = true;
                    aPLB.Caption      = captions[i - 1];
                    aPLB.SymbolColor  = aPLB.Color;
                    aPLB.SymbolStyle  = (PointStyle)idxList[i];

                    legendScheme.LegendBreaks.Add(aPLB);
                }
                legendScheme.HasNoData = false;
                break;

            case ShapeTypes.Polygon:
                idxList = GetEnumList(colors.Length, typeof(HatchStyle));
                for (i = 1; i < colors.Length; i++)
                {
                    PolygonBreak aPGB = new PolygonBreak();
                    aPGB.Color        = colors[i];
                    aPGB.OutlineColor = Color.Gray;
                    aPGB.OutlineSize  = 1.0F;
                    aPGB.DrawFill     = true;
                    aPGB.DrawOutline  = true;
                    aPGB.DrawShape    = true;
                    aPGB.StartValue   = CValues[i - 1];
                    aPGB.EndValue     = aPGB.StartValue;
                    aPGB.Caption      = captions[i - 1];
                    aPGB.Style        = (HatchStyle)idxList[i];

                    legendScheme.LegendBreaks.Add(aPGB);
                }
                legendScheme.HasNoData = false;
                break;
            }
            //legendScheme.breakNum = legendScheme.LegendBreaks.Count;

            return(legendScheme);
        }
        /// <summary>
        /// Create single symbol legend scheme
        /// </summary>
        /// <param name="aST">shape type</param>
        /// <param name="aColor">color</param>
        /// <param name="size">size</param>
        /// <returns>legend scheme</returns>
        public static LegendScheme CreateSingleSymbolLegendScheme(ShapeTypes aST, Color aColor,
                                                                  Single size)
        {
            LegendScheme legendScheme = new LegendScheme(aST);

            legendScheme.LegendType   = LegendType.SingleSymbol;
            legendScheme.ShapeType    = aST;
            legendScheme.MinValue     = 0;
            legendScheme.MaxValue     = 0;
            legendScheme.MissingValue = -9999;
            legendScheme.LegendBreaks = new List <ColorBreak>();
            switch (aST)
            {
            case ShapeTypes.Point:
                PointBreak aPB = new PointBreak();
                aPB.Color        = aColor;
                aPB.OutlineColor = Color.Black;
                aPB.Size         = size;
                aPB.IsNoData     = false;
                aPB.DrawFill     = true;
                aPB.DrawOutline  = true;
                aPB.DrawShape    = true;
                aPB.Style        = PointStyle.Circle;
                aPB.StartValue   = 0;
                aPB.EndValue     = 0;
                aPB.Caption      = "";
                legendScheme.LegendBreaks.Add(aPB);
                break;

            case ShapeTypes.Polyline:
            case ShapeTypes.PolylineZ:
                PolyLineBreak aPLB = new PolyLineBreak();
                aPLB.Color        = aColor;
                aPLB.DrawPolyline = true;
                aPLB.Size         = size;
                aPLB.Style        = LineStyles.Solid;
                aPLB.StartValue   = 0;
                aPLB.EndValue     = 0;
                aPLB.Caption      = "";
                aPLB.SymbolColor  = aColor;
                legendScheme.LegendBreaks.Add(aPLB);
                break;

            case ShapeTypes.Polygon:
                PolygonBreak aPGB = new PolygonBreak();
                aPGB.Color        = aColor;
                aPGB.DrawFill     = true;
                aPGB.DrawOutline  = true;
                aPGB.DrawShape    = true;
                aPGB.OutlineColor = Color.Gray;
                aPGB.OutlineSize  = size;
                aPGB.StartValue   = 0;
                aPGB.EndValue     = 0;
                aPGB.Caption      = "";
                legendScheme.LegendBreaks.Add(aPGB);
                break;
            }
            //legendScheme.BreakNum = legendScheme.LegendBreaks.Count;

            return(legendScheme);
        }
 /// <summary>
 /// Set legend scheme
 /// </summary>
 /// <param name="aLS"></param>
 public void SetLegendScheme(LegendScheme aLS)
 {
     _legendScheme = (LegendScheme)aLS.Clone();
 }
Exemple #14
0
        private void CreateLegendScheme(LegendType aLT, string fieldName)
        {
            if (_ifCreateLegendScheme)
            {
                double     min, max;
                ShapeTypes aST = _legendScheme.ShapeType;

                min = _legendScheme.MinValue;
                max = _legendScheme.MaxValue;
                switch (aLT)
                {
                case LegendType.SingleSymbol:
                    Color aColor = Color.Black;
                    switch (aST)
                    {
                    case ShapeTypes.Point:
                        aColor = Color.Black;
                        break;

                    case ShapeTypes.Polyline:
                    case ShapeTypes.PolylineZ:
                        aColor = Color.Black;
                        break;

                    case ShapeTypes.Polygon:
                    case ShapeTypes.Image:
                        aColor = Color.FromArgb(255, 251, 195);
                        break;
                    }
                    Single size = 0.1F;
                    if (_legendScheme.ShapeType == ShapeTypes.Point)
                    {
                        size = 5;
                    }
                    _legendScheme = LegendManage.CreateSingleSymbolLegendScheme(_legendScheme.ShapeType, aColor,
                                                                                size);

                    TSB_Add.Enabled        = false;
                    TSB_Del.Enabled        = false;
                    TSB_DelAll.Enabled     = false;
                    TSB_Down.Enabled       = false;
                    TSB_Up.Enabled         = false;
                    TSB_MakeBreaks.Enabled = false;
                    TSB_Reverse.Enabled    = false;
                    break;

                case LegendType.UniqueValue:
                    Color[]       colors;
                    List <string> valueList = new List <string>();

                    VectorLayer aLayer      = (VectorLayer)_mapLayer;
                    bool        isDateField = false;
                    Type        colType     = aLayer.AttributeTable.Table.Columns[fieldName].DataType;
                    if (colType == typeof(DateTime))
                    {
                        isDateField = true;
                    }

                    List <string> captions = new List <string>();

                    for (int i = 0; i < aLayer.AttributeTable.Table.Rows.Count; i++)
                    {
                        if (!valueList.Contains(aLayer.AttributeTable.Table.Rows[i][fieldName].ToString()))
                        {
                            valueList.Add(aLayer.AttributeTable.Table.Rows[i][fieldName].ToString());
                            if (isDateField)
                            {
                                captions.Add(((DateTime)aLayer.AttributeTable.Table.Rows[i][fieldName]).ToString("yyyy/M/d"));
                            }
                        }
                    }

                    if (valueList.Count == 1)
                    {
                        MessageBox.Show("The values of all shapes are same!", "Alarm");
                        break;
                    }

                    if (valueList.Count <= 13)
                    {
                        colors = LegendManage.CreateRainBowColors(valueList.Count);
                    }
                    else
                    {
                        colors = LegendManage.CreateRandomColors(valueList.Count);
                    }
                    List <Color> CList = new List <Color>(colors);
                    CList.Insert(0, Color.White);
                    colors = CList.ToArray();

                    if (isDateField)
                    {
                        _legendScheme = LegendManage.CreateUniqValueLegendScheme(valueList, captions, colors, aST, min,
                                                                                 max, _legendScheme.HasNoData, _legendScheme.MissingValue);
                    }
                    else
                    {
                        _legendScheme = LegendManage.CreateUniqValueLegendScheme(valueList, colors,
                                                                                 aST, min, max, _legendScheme.HasNoData, _legendScheme.MissingValue);
                    }

                    _legendScheme.FieldName = fieldName;

                    TSB_Add.Enabled        = true;
                    TSB_Del.Enabled        = true;
                    TSB_DelAll.Enabled     = true;
                    TSB_Down.Enabled       = true;
                    TSB_Up.Enabled         = true;
                    TSB_MakeBreaks.Enabled = true;
                    TSB_Reverse.Enabled    = true;
                    break;

                case LegendType.GraduatedColor:
                    aLayer = (VectorLayer)_mapLayer;
                    double[] S = new double[aLayer.AttributeTable.Table.Rows.Count];
                    for (int i = 0; i < S.Length; i++)
                    {
                        S[i] = double.Parse(aLayer.AttributeTable.Table.Rows[i][fieldName].ToString());
                    }
                    MIMath.GetMaxMinValue(S, _legendScheme.MissingValue, ref min, ref max);


                    if (min == max)
                    {
                        MessageBox.Show("The values of all shapes are same!", "Alarm");
                        break;
                    }

                    double[] CValues;
                    CValues = LegendManage.CreateContourValues(min, max);
                    colors  = LegendManage.CreateRainBowColors(CValues.Length + 1);

                    _legendScheme = LegendManage.CreateGraduatedLegendScheme(CValues, colors,
                                                                             aST, min, max, _legendScheme.HasNoData, _legendScheme.MissingValue);
                    _legendScheme.FieldName = fieldName;

                    TSB_Add.Enabled        = true;
                    TSB_Del.Enabled        = true;
                    TSB_DelAll.Enabled     = true;
                    TSB_Down.Enabled       = true;
                    TSB_Up.Enabled         = true;
                    TSB_MakeBreaks.Enabled = true;
                    TSB_Reverse.Enabled    = true;
                    break;
                }

                //ShowLegendScheme(_legendScheme);
                //DataGridView1.Refresh();
                legendView1.LegendScheme = _legendScheme;
                legendView1.Invalidate();
            }
        }
Exemple #15
0
        private void TSB_Reverse_Click(object sender, EventArgs e)
        {
            LegendScheme aLS = (LegendScheme)_legendScheme.Clone();
            int          aNum;

            if (_legendScheme.HasNoData)
            {
                aNum = _legendScheme.BreakNum - 1;
            }
            else
            {
                aNum = _legendScheme.BreakNum;
            }
            _legendScheme.LegendBreaks.Reverse(0, aNum);

            //switch (_legendScheme.ShapeType)
            //{
            //    case ShapeType.Point:
            //        PointBreak aPB = new PointBreak();
            //        PointBreak bPB = new PointBreak();
            //        for (int i = 0; i < aNum; i++)
            //        {
            //            if (i == aNum - i - 1)
            //            {
            //                continue;
            //            }
            //            else
            //            {
            //                aPB = (PointBreak)_legendScheme.LegendBreaks[i];
            //                bPB = (PointBreak)aLS.LegendBreaks[aNum - i - 1];
            //                aPB.color = bPB.color;
            //                aPB.drawFill = bPB.drawFill;
            //                aPB.drawOutline = bPB.drawOutline;
            //                aPB.drawPoint = bPB.drawPoint;
            //                aPB.isNoData = bPB.isNoData;
            //                aPB.outlineColor = bPB.outlineColor;
            //                aPB.size = bPB.size;
            //                aPB.style = bPB.style;
            //                _legendScheme.LegendBreaks[i] = aPB;
            //            }
            //        }
            //        break;
            //    case ShapeType.Polyline:
            //        PolyLineBreak aPLB = new PolyLineBreak();
            //        PolyLineBreak bPLB = new PolyLineBreak();
            //        for (int i = 0; i < aNum; i++)
            //        {
            //            if (i == aNum - i - 1)
            //            {
            //                continue;
            //            }
            //            else
            //            {
            //                aPLB = (PolyLineBreak)_legendScheme.LegendBreaks[i];
            //                bPLB = (PolyLineBreak)aLS.LegendBreaks[aNum - i - 1];
            //                aPLB.color = bPLB.color;
            //                aPLB.size = bPLB.size;
            //                aPLB.style = bPLB.style;
            //                aPLB.drawLine = bPLB.drawLine;
            //                _legendScheme.LegendBreaks[i] = aPLB;
            //            }
            //        }
            //        break;
            //    case ShapeType.Polygon:
            //        PolygonBreak aPGB = new PolygonBreak();
            //        PolygonBreak bPGB = new PolygonBreak();
            //        for (int i = 0; i < aNum; i++)
            //        {
            //            if (i == aNum - i - 1)
            //            {
            //                continue;
            //            }
            //            else
            //            {
            //                aPGB = (PolygonBreak)_legendScheme.LegendBreaks[i];
            //                bPGB = (PolygonBreak)aLS.LegendBreaks[aNum - i - 1];
            //                aPGB.color = bPGB.color;
            //                aPGB.drawFill = bPGB.drawFill;
            //                aPGB.drawOutline = bPGB.drawOutline;
            //                aPGB.drawPolygon = bPGB.drawPolygon;
            //                aPGB.outlineColor = bPGB.outlineColor;
            //                aPGB.outlineSize = bPGB.outlineSize;
            //                _legendScheme.LegendBreaks[i] = aPGB;
            //            }
            //        }
            //        break;
            //}


            legendView1.Update(_legendScheme);
        }
Exemple #16
0
 /// <summary>
 /// Set legend scheme
 /// </summary>
 /// <param name="aLS"></param>
 public void SetLegendScheme(LegendScheme aLS)
 {
     _legendScheme            = (LegendScheme)aLS.Clone();
     legendView1.LegendScheme = _legendScheme;
 }