private bool DoJenksFisherCategorization(int colorIndex, bool multiAOI = false) { if (txtCategoryCount.Text.Length > 0) { _sheetMapSummary.Clear(); _categoryItems.Clear(); _dataValues = ComputeDataValues(multiAOI); _dataValues.Sort(); var listBreaks = JenksFisher.CreateJenksFisherBreaksArray(_dataValues, int.Parse(txtCategoryCount.Text)); var n = 0; var lower = listBreaks.Min(); var upper = 0D; int row; System.Drawing.Color color; _categories.Clear(); ColorBlend blend = (ColorBlend)icbColorScheme.ColorSchemes.List[colorIndex]; _scheme = ColorSchemes.ColorBlend2ColorScheme(blend); //make categories from the breaks defined in Jenk's-Fisher's //add the category range and color to a datagridview CategoryItem ci; foreach (var item in listBreaks) { if (n > 0) { upper = item; color = AddCategory(lower, upper); ci = new CategoryItem(); ci.Upper = item; ci.Color = color; ci.Lower = lower; ci.ClassSize = GetClassSize(lower, upper).ToString(); lower = item; _categoryItems.Add(ci); } n++; } //add the last category to the datagridview color = AddCategory(upper, _dataValues.Max() + 1); ci = new CategoryItem(); ci.Color = color; ci.Lower = listBreaks.Max(); ci.Upper = _dataValues.Max(); ci.ClassSize = GetClassSize(listBreaks.Max(), 0, true).ToString(); _categoryItems.Add(ci); //add an empty null category AddNullCategory(); return(_categoryItems.Count > 0); } else { MessageBox.Show("Specify number of categories", "GPX Manager", MessageBoxButton.OK, MessageBoxImage.Information); } return(false); }
/// <summary> /// 应用所选的颜色方案 /// </summary> private void ApplyColorScheme2Categories() { if (_shapefile.Categories.Count > 0) { MapWinGIS.ColorScheme scheme = null; if (icbCategories.SelectedIndex >= 0) { ColorBlend blend = (ColorBlend)icbCategories.ColorSchemes.List[icbCategories.SelectedIndex]; scheme = ColorSchemes.ColorBlend2ColorScheme(blend); // saving the settings //MWLite.Symbology.Layer layer = Globals.Legend.Layers.ItemByHandle(_layerHandle); //_settings.CategoriesColorScheme = blend; } else { return; } if (chkRandomColors.Checked) { _shapefile.Categories.ApplyColorScheme(MapWinGIS.tkColorSchemeType.ctSchemeRandom, scheme); } else { _shapefile.Categories.ApplyColorScheme(MapWinGIS.tkColorSchemeType.ctSchemeGraduated, scheme); } MapWinGIS.ShapefileCategories categories = _shapefile.Categories; //绘制catagorise选项 if (chkSetGradient.Checked) { for (int i = 0; i < categories.Count; i++) { ShapeDrawingOptions options = categories.get_Item(i).DrawingOptions; options.SetGradientFill(options.FillColor, 75); options.FillType = tkFillType.ftGradient; } } else { for (int i = 0; i < categories.Count; i++) { ShapeDrawingOptions options = categories.get_Item(i).DrawingOptions; options.FillColor2 = options.FillColor; options.FillType = tkFillType.ftStandard; } } } }
private void UpdateFieldColors() { List <ColorBlend> schemes = icbColors.ColorSchemes.List; if (schemes != null && icbColors.SelectedIndex >= 0) { ColorBlend blend = (ColorBlend)schemes[icbColors.SelectedIndex]; MapWinGIS.ColorScheme scheme = ColorSchemes.ColorBlend2ColorScheme(blend); if (scheme != null) { for (int i = 0; i < _charts.NumFields; i++) { MapWinGIS.ChartField field = _charts.get_Field(i); double value = (double)(i) / (double)(_charts.NumFields - 1); field.Color = scheme.get_GraduatedColor(value); } } } }
/// <summary> /// Generation of labels categories /// </summary> private void btnOk_Click(object sender, EventArgs e) { if (cboField.SelectedIndex < 0) { Globals.MessageBoxInformation("No field for generation was selected"); this.DialogResult = DialogResult.None; return; } int count = 0; if (!Int32.TryParse(cboCategoriesCount.Text, out count)) { Globals.MessageBoxInformation("The entered categories count isn't a number"); this.DialogResult = DialogResult.None; return; } string fieldName = cboField.SelectedItem.ToString(); int index = -1; for (int i = 0; i < m_shapefile.NumFields; i++) { if (m_shapefile.get_Field(i).Name == fieldName) { index = i; break; } } if (index == -1) { return; } m_shapefile.Labels.GenerateCategories(index, (MapWinGIS.tkClassificationType)cboClassificationType.SelectedIndex, count); if (chkUseVariableSize.Checked) { int numCategories = m_shapefile.Labels.NumCategories; double step = (double)(udMaxSize.Value - udMinSize.Value) / ((double)numCategories - 1); for (int i = 0; i < numCategories; i++) { m_shapefile.Labels.get_Category(i).FontSize = (int)udMinSize.Value + Convert.ToInt32(i * step); } } if (chkGraduatedFrame.Checked) { ColorBlend blend = (ColorBlend)icbFrame.ColorSchemes.List[icbFrame.SelectedIndex]; MapWinGIS.ColorScheme scheme = ColorSchemes.ColorBlend2ColorScheme(blend); tkColorSchemeType type = chkRandomColors.Checked ? tkColorSchemeType.ctSchemeRandom : tkColorSchemeType.ctSchemeGraduated; m_shapefile.Labels.ApplyColorScheme2(type, scheme, tkLabelElements.leFrameBackground); } for (int i = 0; i < m_shapefile.Labels.NumCategories; i++) { m_shapefile.Labels.get_Category(i).FrameVisible = chkGraduatedFrame.Checked; } m_shapefile.Labels.ApplyCategories(); SaveSettings(); }
/// <summary> /// Generates shapefile categories according to specified options /// </summary> private void btnOk_Click(object sender, EventArgs e) { if (cboField.SelectedIndex < 0) { Globals.MessageBoxInformation("No field for generation was selected."); this.DialogResult = DialogResult.None; return; } int count; if (!Int32.TryParse(cboCategoriesCount.Text, out count)) { Globals.MessageBoxError("Number of categories isn't a valid interger."); return; } MapWinGIS.ShapefileCategories categories = _shapefile.Categories; int index = ((ComboItem)cboField.SelectedItem).RealIndex; categories.Generate(index, (MapWinGIS.tkClassificationType)cboClassificationType.SelectedIndex, count); categories.Caption = "Categories: " + _shapefile.get_Field(index).Name; if (chkUseVariableSize.Checked) { if (_shapefile.ShapefileType == ShpfileType.SHP_POINT || _shapefile.ShapefileType == ShpfileType.SHP_MULTIPOINT) { double step = (double)(udMaxSize.Value - udMinSize.Value) / ((double)categories.Count - 1); for (int i = 0; i < categories.Count; i++) { categories.get_Item(i).DrawingOptions.PointSize = (int)udMinSize.Value + Convert.ToInt32(i * step); } } else if (_shapefile.ShapefileType == ShpfileType.SHP_POLYLINE) { double step = (double)(udMaxSize.Value + udMinSize.Value) / (double)categories.Count; for (int i = 0; i < categories.Count; i++) { categories.get_Item(i).DrawingOptions.LineWidth = (int)udMinSize.Value + Convert.ToInt32(i * step); } } } MapWinGIS.ColorScheme scheme = null; if (icbColorScheme.SelectedIndex >= 0) { ColorBlend blend = (ColorBlend)icbColorScheme.ColorSchemes.List[icbColorScheme.SelectedIndex]; scheme = ColorSchemes.ColorBlend2ColorScheme(blend); } tkColorSchemeType type = chkRandomColors.Checked ? tkColorSchemeType.ctSchemeRandom : tkColorSchemeType.ctSchemeGraduated; _shapefile.Categories.ApplyColorScheme(type, scheme); if (chkSetGradient.Checked) { for (int i = 0; i < categories.Count; i++) { ShapeDrawingOptions options = categories.get_Item(i).DrawingOptions; options.SetGradientFill(options.FillColor, 75); options.FillType = tkFillType.ftGradient; } } _shapefile.Categories.ApplyExpressions(); SaveSettings(); }