private void UpdateSymbology(IFeatureLayer mapLayer, string columnName) { var scheme = new PointScheme(); scheme.ClearCategories(); var settings = scheme.EditorSettings; settings.ClassificationType = ClassificationType.Custom; var colors = new[] { Color.Aqua, Color.Blue, Color.Brown, Color.Cyan, Color.Fuchsia, Color.LightSalmon, Color.Olive, Color.Wheat, Color.DodgerBlue }; // Find min/max value in valueField var minValue = double.MaxValue; var maxValue = double.MinValue; foreach (DataRow row in mapLayer.DataSet.DataTable.Rows) { double value; try { value = Convert.ToDouble(row[columnName]); } catch { value = 0; } if (value < minValue) { minValue = value; } if (value > maxValue) { maxValue = value; } } const double EPSILON = 0.00001; if (Math.Abs(minValue - double.MaxValue) < EPSILON) { minValue = 0.0; } if (Math.Abs(maxValue - double.MinValue) < EPSILON) { maxValue = 0.0; } var fracLength = maxValue - minValue > 10? 0 : 1; // Set number of categories const int categoriesCount = 3; var categorieStep = (maxValue - minValue) / categoriesCount; // value step in filter const int imageStep = 5; var imageSize = 10; // start image size var imageColor = colors[new Random().Next(0, colors.Length - 1)]; for (int i = 0; i < categoriesCount; i++) { var min = minValue + categorieStep * i; var max = min + categorieStep; if (max >= maxValue) { max = maxValue + 1; } min = Math.Round(min, fracLength); max = Math.Round(max, fracLength); // Fix possible round problems on interval borders if (i == 0 && min > minValue) { min--; } if (i == categoriesCount - 1 && max < maxValue) { max++; } imageSize += imageStep; var baseFilter = string.Format("[{0}] >= {1} and [{0}] < {2}", columnName, fracLength == 0 ? (int)min : min, fracLength == 0 ? (int)max : max); var legendText = string.Format("[{0}, {1})", fracLength == 0 ? (int)min : min, fracLength == 0 ? (int)max : max); var mySymbolizer = new PointSymbolizer(imageColor, PointShape.Ellipse, imageSize); var myCategory = new PointCategory(mySymbolizer) { FilterExpression = baseFilter.Replace(",", "."), LegendText = legendText, }; scheme.AddCategory(myCategory); } mapLayer.Symbology = scheme; }
private static IPointScheme CreateSymbology(string servCode, IFeatureSet featureSet) { Debug.Assert(featureSet != null); var scheme = new PointScheme(); scheme.ClearCategories(); var settings = scheme.EditorSettings; settings.ClassificationType = ClassificationType.Custom; const string valueField = "ValueCount"; // Find min/max value in valueField var minValue = int.MaxValue; var maxValue = int.MinValue; foreach (DataRow row in featureSet.DataTable.Rows) { int value; try { value = Convert.ToInt32(row[valueField]); } catch { value = 0; } if (value < minValue) { minValue = value; } if (value > maxValue) { maxValue = value; } } if (minValue == int.MaxValue) { minValue = 0; } if (maxValue == int.MinValue) { maxValue = 0; } // Calculate number of categories int categoriesCount; var length = maxValue - minValue; if (length < 50) { categoriesCount = 1; } else if (length < 100) { categoriesCount = 2; } else { categoriesCount = 3; } var categorieStep = (maxValue - minValue) / categoriesCount + 1; // value step in filter const int imageStep = 5; var imageSize = 5; var imageHelper = new WebServices.ServiceIconHelper(Settings.Instance.SelectedHISCentralURL); // we need it only to get image var image = imageHelper.GetImageForService(servCode); const string seriesID = "SeriesID"; var needDownloadedCategories = featureSet.DataTable.Columns.Contains(seriesID); for (int i = 0; i < categoriesCount; i++) { var min = minValue - 1; var max = minValue + categorieStep; if (max > maxValue) { max = maxValue; } minValue = max + 1; imageSize += imageStep; var baseFilter = string.Format("[{0}] > {1} and [{0}] <= {2}", valueField, min, max); var filterEx = needDownloadedCategories ? baseFilter + string.Format(" AND ([{0}] is null)", seriesID) : baseFilter; var legendText = string.Format("({0}, {1}]", min, max); var mySymbolizer = new PointSymbolizer(image, imageSize); var myCategory = new PointCategory(mySymbolizer) { FilterExpression = filterEx, LegendText = legendText, SelectionSymbolizer = new PointSymbolizer(image, imageSize + 2) }; myCategory.SelectionSymbolizer.SetFillColor(Color.Yellow); scheme.AddCategory(myCategory); // add category for downloaded if (needDownloadedCategories) { mySymbolizer = new PointSymbolizer(image, imageSize); mySymbolizer.SetOutline(Color.Green, 3); filterEx = string.Format("{0} AND not([{1}] is null)", baseFilter, seriesID); legendText = myCategory.LegendText + " (downloaded)"; var categorieForDownload = new PointCategory(mySymbolizer) { FilterExpression = filterEx, LegendText = legendText, SelectionSymbolizer = new PointSymbolizer(image, imageSize + 2) }; categorieForDownload.SelectionSymbolizer.SetFillColor(Color.Yellow); scheme.AddCategory(categorieForDownload); } } return(scheme); }