public void CloneQuantityThemeWithNoDataValues() { var quantityTheme = new QuantityTheme("aa",new VectorStyle()){ NoDataValues = new List<double> { -9999 } }; var quantityThemeClone = quantityTheme.Clone(); Assert.AreEqual(quantityTheme.NoDataValues, ((QuantityTheme)quantityThemeClone).NoDataValues); }
public void ShowRegularGridWithQuantityThemeOnMap() { IRegularGridCoverage grid2D = new RegularGridCoverage(200, 200, 10, 10) { Name = "pressure" }; double[] values = new double[grid2D.SizeX * grid2D.SizeY]; double min = 0; double max = 0; for (int i = 0; i < values.Length; i++) { values[i] = i; if (values[i] > max) { max = values[i]; } if (values[i] < min) { min = values[i]; } } grid2D.SetValues(values); var map = new Map(); var rasterLayer = new RegularGridCoverageLayer { Grid = grid2D }; var defaultStyle = new VectorStyle { GeometryType = typeof(IPolygon), Line = Pens.SeaGreen }; double interval = (max - min) / 10; var intervalList = new List <Interval>(); double start = min; double stop = min + interval; for (int i = 0; i < 10; i++) { intervalList.Add(new Interval(start, stop)); start = stop; stop += interval; } QuantityTheme quantityTheme = ThemeFactory.CreateQuantityTheme(grid2D.Components[0].Name, defaultStyle, ColorBlend.BlueToGreen, 10, intervalList ); rasterLayer.Theme = quantityTheme; map.Layers.Add(rasterLayer); MapTestHelper.ShowModal(map); }
public void QuantityThemeColorTest() { var defaultStyle = GenerateVectorStyle(Brushes.Black); var quantityTheme = new QuantityTheme("test", defaultStyle); var redStyle = GenerateVectorStyle(Brushes.Red); var whiteStyle = GenerateVectorStyle(Brushes.White); var blueStyle = GenerateVectorStyle(Brushes.Blue); //add styles in random order quantityTheme.AddStyle(redStyle, new Interval(0.0, 1.0)); quantityTheme.AddStyle(blueStyle, new Interval(2.0, 3.0)); quantityTheme.AddStyle(whiteStyle, new Interval(1.0, 2.0)); quantityTheme.NoDataValues = new[] { -999.0 }; //value within interval Assert.IsTrue(CompareRGBColor(Color.Red, quantityTheme.GetFillColor(0.5))); Assert.IsTrue(CompareRGBColor(Color.White, quantityTheme.GetFillColor(1.5))); Assert.IsTrue(CompareRGBColor(Color.Blue, quantityTheme.GetFillColor(2.5))); //no data value Assert.IsTrue(CompareRGBColor(Pens.Transparent.Color, quantityTheme.GetFillColor(-999.0))); }
public void QuantityThemeColorTest() { var defaultStyle = GenerateVectorStyle(Brushes.Black); var quantityTheme = new QuantityTheme("test", defaultStyle); var redStyle = GenerateVectorStyle(Brushes.Red); var whiteStyle = GenerateVectorStyle(Brushes.White); var blueStyle = GenerateVectorStyle(Brushes.Blue); //add styles in random order quantityTheme.AddStyle(redStyle, new Interval(0.0, 1.0)); quantityTheme.AddStyle(blueStyle, new Interval(2.0, 3.0)); quantityTheme.AddStyle(whiteStyle, new Interval(1.0, 2.0)); quantityTheme.NoDataValues = new[] {-999.0}; //value within interval Assert.IsTrue(CompareRGBColor(Color.Red, quantityTheme.GetFillColor(0.5))); Assert.IsTrue(CompareRGBColor(Color.White, quantityTheme.GetFillColor(1.5))); Assert.IsTrue(CompareRGBColor(Color.Blue, quantityTheme.GetFillColor(2.5))); //no data value Assert.IsTrue(CompareRGBColor(Pens.Transparent.Color, quantityTheme.GetFillColor(-999.0))); }
private static themeQuantity GetThemeQuantity(QuantityTheme theme) { // QuantityTheme properties var quanThemeItems = new List <themeItem>(); foreach (QuantityThemeItem item in theme.ThemeItems) { // Add theme items (style and label) to the QuantityTheme // NOTE: The actual Category of this specific ThemeItem is always equal to the Label (no need to store it twice) // NOTE: Symbol isn't stored but generated during rebuilding in the QuantityThemeItem.AddStyle() method var quanThemeItem = new themeItem { label = item.Label, style = GetStyleConverter().ConvertToString(item.Style), intervalMinValue = item.Interval.Min, intervalMaxValue = item.Interval.Max }; quanThemeItems.Add(quanThemeItem); } var themeQuantity = new themeQuantity { columnName = theme.AttributeName, defaultStyle = GetDefaultStyle(theme), noDataValues = GetNoDataValues(theme.NoDataValues), noDataValueType = GetNoDataValueType(theme.NoDataValues), quantityThemeItems = quanThemeItems.ToArray() }; return(themeQuantity); }
public void CloneQuantityThemeWithNoDataValues() { var quantityTheme = new QuantityTheme("aa", new VectorStyle()) { NoDataValues = new List <double> { -9999 } }; var quantityThemeClone = quantityTheme.Clone(); Assert.AreEqual(quantityTheme.NoDataValues, ((QuantityTheme)quantityThemeClone).NoDataValues); }
private static ITheme CreateQuantityTheme <T>(Legend legend, Ranges <T> ranges) { QuantityTheme theme = new QuantityTheme(legend.columnName, new VectorStyle()); foreach (Range <T> range in ranges.ranges) { Interval interval = null; if (typeof(T) == typeof(double)) { interval = new Interval(range.doubleMinValue, range.doubleMaxValue); } else { interval = new Interval(range.intMinValue, range.intMaxValue); } VectorStyle style = new VectorStyle(); style.Fill = new SolidBrush(range.color); QuantityThemeItem themeItem = new QuantityThemeItem(interval, style); theme.ThemeItems.Add(themeItem); } return(theme); }
private static QuantityTheme GetQuantityTheme(theme theme) { var themeQuantity = (themeQuantity)theme.Item; var quanTheme = new QuantityTheme(themeQuantity.columnName, GetDefaultStyle(theme)) { NoDataValues = ConvertNoDataValues(themeQuantity.noDataValues, themeQuantity.noDataValueType) }; foreach (themeItem quanThemeItem in themeQuantity.quantityThemeItems) { var themeStyle = GetStyle(quanThemeItem); var interval = new Interval(quanThemeItem.intervalMinValue, quanThemeItem.intervalMaxValue); var themeItem = new QuantityThemeItem(interval, themeStyle) { Label = quanThemeItem.label }; quanTheme.ThemeItems.Add(themeItem); } return(quanTheme); }
public static QuantityTheme CreateQuantityTheme(string attribute, VectorStyle defaultStyle, ColorBlend blend, int numberOfClasses, IList<Interval> intervals, float minSize, float maxSize, bool skipColors, bool skipSizes) { if (defaultStyle == null) { defaultStyle = new VectorStyle(); defaultStyle.GeometryType = typeof(IPolygon); } var quantityTheme = new QuantityTheme(attribute, defaultStyle); var totalMinValue = (float) intervals[0].Min; var totalMaxValue = (float) intervals[intervals.Count - 1].Max; if (totalMinValue == totalMaxValue) { return null; } for (int i = 0; i < numberOfClasses; i++) { Color color = numberOfClasses > 1 ? blend.GetColor(1 - (float) i/(numberOfClasses - 1)) : ((SolidBrush) defaultStyle.Fill).Color; float size = defaultStyle.Line.Width; if (!skipSizes) { var minValue = (float) intervals[i].Min; var maxValue = (float) intervals[i].Max; float width = maxValue - minValue; float mean = minValue + 0.5f * width; float fraction = (mean - totalMinValue) / (totalMaxValue - totalMinValue); size = minSize + fraction * (maxSize - minSize); } var vectorStyle = new VectorStyle { GeometryType = defaultStyle.GeometryType }; if (defaultStyle.GeometryType == typeof(IPoint)) { if (skipColors) { color = ((SolidBrush)defaultStyle.Fill).Color; } vectorStyle.Fill = new SolidBrush(color); vectorStyle.Shape = defaultStyle.Shape; if (!skipSizes) { vectorStyle.ShapeSize = Convert.ToInt32(size); vectorStyle.Line.Width = size; } } else if ((defaultStyle.GeometryType == typeof(IPolygon)) || (defaultStyle.GeometryType == typeof(IMultiPolygon))) { if (skipColors) { color = ((SolidBrush)defaultStyle.Fill).Color; } vectorStyle.Fill = new SolidBrush(color); vectorStyle.Line = CreatePen(color, size, defaultStyle.Line); vectorStyle.Outline.Width = (defaultStyle.Outline.Width - defaultStyle.Line.Width) + size; } else if ((defaultStyle.GeometryType == typeof(ILineString)) || (defaultStyle.GeometryType == typeof(IMultiLineString))) { if (skipColors) { color = defaultStyle.Line.Color; } vectorStyle.Line = CreatePen(color, size, defaultStyle.Line); vectorStyle.Outline.Width = (defaultStyle.Outline.Width - defaultStyle.Line.Width) + size; } else { vectorStyle.Fill = new SolidBrush(color); } quantityTheme.AddStyle(vectorStyle, intervals[i]); } return quantityTheme; }
private static themeQuantity GetThemeQuantity(QuantityTheme theme) { // QuantityTheme properties var quanThemeItems = new List<themeItem>(); foreach (QuantityThemeItem item in theme.ThemeItems) { // Add theme items (style and label) to the QuantityTheme // NOTE: The actual Category of this specific ThemeItem is always equal to the Label (no need to store it twice) // NOTE: Symbol isn't stored but generated during rebuilding in the QuantityThemeItem.AddStyle() method var quanThemeItem = new themeItem { label = item.Label, style = GetStyleConverter().ConvertToString(item.Style), intervalMinValue = item.Interval.Min, intervalMaxValue = item.Interval.Max }; quanThemeItems.Add(quanThemeItem); } var themeQuantity = new themeQuantity { columnName = theme.AttributeName, defaultStyle = GetDefaultStyle(theme), noDataValues = GetNoDataValues(theme.NoDataValues), noDataValueType = GetNoDataValueType(theme.NoDataValues), quantityThemeItems = quanThemeItems.ToArray() }; return themeQuantity; }
private static QuantityTheme GetQuantityTheme(theme theme) { var themeQuantity = (themeQuantity) theme.Item; var quanTheme = new QuantityTheme(themeQuantity.columnName, GetDefaultStyle(theme)) { NoDataValues = ConvertNoDataValues(themeQuantity.noDataValues, themeQuantity.noDataValueType) }; foreach (themeItem quanThemeItem in themeQuantity.quantityThemeItems) { var themeStyle = GetStyle(quanThemeItem); var interval = new Interval(quanThemeItem.intervalMinValue, quanThemeItem.intervalMaxValue); var themeItem = new QuantityThemeItem(interval, themeStyle) {Label = quanThemeItem.label}; quanTheme.ThemeItems.Add(themeItem); } return quanTheme; }