private void CategorizeCities(IMapPointLayer alayer) { PointScheme lScheme = new PointScheme(); lScheme.Categories.Clear(); PointCategory smallSize = new PointCategory(Color.Blue, DotSpatial.Symbology.PointShape.Rectangle, 4); smallSize.FilterExpression = "[Area] < 1e+08"; smallSize.LegendText = "Small Cities"; lScheme.AddCategory(smallSize); PointCategory largeSize = new PointCategory(Color.Yellow, DotSpatial.Symbology.PointShape.Star, 16); largeSize.FilterExpression = "[Area] >= 1e+08"; largeSize.LegendText = "Large Cities"; lScheme.AddCategory(largeSize); alayer.Symbology = lScheme; }
override protected void setSymbolizer() { int baseWidth = 48; PointScheme ftrScheme = new PointScheme(); PointCategory catDef = new PointCategory(Properties.Resources.feature, baseWidth); catDef.LegendText = "No Info"; catDef.SelectionSymbolizer.ScaleMode = ScaleMode.Geographic; catDef.SelectionSymbolizer.SetOutline(Color.Cyan, baseWidth / 4); catDef.Symbolizer.ScaleMode = ScaleMode.Geographic; ftrScheme.AddCategory(catDef); Image[] images = { Properties.Resources.feature, Properties.Resources.important, Properties.Resources.question, Properties.Resources.problem, Properties.Resources.ramp, Properties.Resources.sidewalk, Properties.Resources.feature, Properties.Resources.problem, Properties.Resources.pooling, Properties.Resources.crash }; string[] iconNames = { "feature", "important", "question", "problem", "ramp", "sidewalk", "other", "road", "drainage", "accident" }; for (int i = 0; i < images.Length; i++) { PointCategory cat = new PointCategory(images[i], baseWidth); cat.FilterExpression = "[TAMSICON] = '" + iconNames[i] + "'"; cat.SelectionSymbolizer.ScaleMode = ScaleMode.Geographic; cat.SelectionSymbolizer.SetOutline(Color.Cyan, baseWidth / 4); cat.Symbolizer.ScaleMode = ScaleMode.Geographic; ftrScheme.AddCategory(cat); } ((MapPointLayer)Layer).Symbology = ftrScheme; ((MapPointLayer)Layer).ApplyScheme(ftrScheme); }
/// <summary> /// Translates the given style as point style and adds it to the given point scheme. /// </summary> /// <param name="scheme">The scheme the style gets added to.</param> /// <param name="labelScheme">The scheme the label definitions gets added to.</param> /// <param name="style">The style that gets translated.</param> private static void TranslatePointStyle(PointScheme scheme, ILabelScheme labelScheme, string style) { if (string.IsNullOrWhiteSpace(style)) { return; } var myStyle = style; int index = myStyle.IndexOf("(", StringComparison.Ordinal); if (index < 1) { return; } var toolname = myStyle.Substring(0, index); myStyle = myStyle.Substring(index + 1); switch (toolname) { case "PEN": { var color = GetColor(ref myStyle, Parameters.Color); var width = GetWidth(ref myStyle); var cat = new PointCategory(color, Symbology.PointShape.Rectangle, width) { FilterExpression = $"[style] = '{style}'", LegendText = style, Symbolizer = { ScaleMode = ScaleMode.Simple, Smoothing = false } }; scheme.AddCategory(cat); break; } case "LABEL": { var fontSize = GetFontSize(ref myStyle); var fontColor = GetColor(ref myStyle, Parameters.Color); var boxColor = GetColor(ref myStyle, Parameters.BoxColor); var haloColor = GetColor(ref myStyle, Parameters.HaloColor); var shadowColor = GetColor(ref myStyle, Parameters.ShadowColor); var angle = GetAngle(ref myStyle); var font = GetFontName(ref myStyle); var orientation = GetOrientation(ref myStyle); // create a transparent point category because the point is only used to position the label var cat = new PointCategory(Color.Transparent, Symbology.PointShape.Rectangle, 1) { FilterExpression = $"[style] = '{style}'", LegendText = style, Symbolizer = { ScaleMode = ScaleMode.Simple, Smoothing = false } }; scheme.AddCategory(cat); // create the label category only if the text column exists, otherwise we don't know where to take the text from if (hasTextField) { var lcat = new LabelCategory { Name = style, Expression = "[Text]", FilterExpression = $"[style] = '{style}'", Symbolizer = { ScaleMode = ScaleMode.Simple, Alignment = StringAlignment.Center, FontColor = fontColor, FontSize = (float)fontSize, Orientation = orientation } }; if (!string.IsNullOrWhiteSpace(font)) { lcat.Symbolizer.FontFamily = font; } if (angle != 0) { lcat.Symbolizer.Angle = angle; lcat.Symbolizer.UseAngle = true; } if (haloColor != Color.Empty) { lcat.Symbolizer.HaloColor = haloColor; lcat.Symbolizer.HaloEnabled = true; } if (boxColor != Color.Empty) { lcat.Symbolizer.BackColor = boxColor; lcat.Symbolizer.BackColorEnabled = true; } if (shadowColor != Color.Empty) { lcat.Symbolizer.DropShadowColor = shadowColor; lcat.Symbolizer.DropShadowEnabled = true; } labelScheme.Categories.Add(lcat); } break; } default: throw new NotImplementedException($"The translation of the point tool {toolname} is not yet implemented."); } }
/// <summary> /// Translates the style strings from the list to DotSpatial style categories and adds them to the given layer. /// </summary> /// <param name="layer">The layer the styles get added to.</param> /// <param name="styles">The style strings that should get translated.</param> public static void TranslateStyles(IMapFeatureLayer layer, IList <string> styles) { var featureType = layer.DataSet.FeatureType; switch (featureType) { case FeatureType.MultiPoint: case FeatureType.Point: { // create the scheme var scheme = new PointScheme(); scheme.Categories.Clear(); scheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues; scheme.EditorSettings.FieldName = "style"; scheme.LegendText = "Point"; // add the default category var cat = new PointCategory(Color.Black, Symbology.PointShape.Rectangle, 5) { LegendText = "default", Symbolizer = { ScaleMode = ScaleMode.Simple, Smoothing = false } }; scheme.AddCategory(cat); var labelLayer = new MapLabelLayer(); labelLayer.Symbology.Categories.Clear(); bool needsLabels = styles.Any(_ => !string.IsNullOrWhiteSpace(_) && _.StartsWith("LABEL")); foreach (var style in styles) { TranslatePointStyle(scheme, labelLayer.Symbology, style); } // assign the scheme layer.Symbology = scheme; // assign the label layer if needed if (needsLabels) { layer.LabelLayer = labelLayer; layer.ShowLabels = true; layer.LabelLayer.CreateLabels(); } layer.DataSet.UpdateExtent(); layer.DataSet.InitializeVertices(); layer.AssignFastDrawnStates(); break; } case FeatureType.Line: { // create the scheme var scheme = new LineScheme(); scheme.Categories.Clear(); scheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues; scheme.EditorSettings.FieldName = "style"; scheme.LegendText = "Line"; // add the default category var cat = new LineCategory(Color.Black, 1) { LegendText = "default", Symbolizer = { ScaleMode = ScaleMode.Simple, Smoothing = false } }; scheme.AddCategory(cat); // add the categories from the file foreach (var style in styles) { TranslateLineStyle(scheme, style); } // assign the scheme layer.Symbology = scheme; layer.DataSet.UpdateExtent(); layer.DataSet.InitializeVertices(); layer.AssignFastDrawnStates(); break; } case FeatureType.Polygon: { // create the scheme var scheme = new PolygonScheme(); scheme.Categories.Clear(); scheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues; scheme.EditorSettings.FieldName = "style"; scheme.LegendText = "Polygon"; // add the default category var cat = new PolygonCategory(Color.GhostWhite, Color.Black, 1) { LegendText = "default", Symbolizer = { ScaleMode = ScaleMode.Simple, Smoothing = false } }; scheme.AddCategory(cat); // add the categories from the file foreach (var style in styles) { TranslatePolygonStyle(scheme, style); } // assign the scheme layer.Symbology = scheme; layer.DataSet.UpdateExtent(); layer.DataSet.InitializeVertices(); layer.AssignFastDrawnStates(); break; } default: throw new ArgumentOutOfRangeException(nameof(featureType), featureType, null); } }
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); }