SharpMap.Rendering.Thematics.GradientTheme.GetStyle C# (CSharp) Method

GetStyle() public method

Returns the style based on a numeric DataColumn, where style properties are linearly interpolated between max and min values.
public GetStyle ( SharpMap row ) : SharpMap.Styles.IStyle
row SharpMap Feature
return SharpMap.Styles.IStyle
        public SharpMap.Styles.IStyle GetStyle(SharpMap.Data.FeatureDataRow row)
        {
            double attr = 0;
            try { attr = Convert.ToDouble(row[this._ColumnName]); }
            catch { throw new ApplicationException("Invalid Attribute type in Gradient Theme - Couldn't parse attribute (must be numerical)"); }
            if (_minStyle.GetType() != _maxStyle.GetType())
                throw new ArgumentException("MinStyle and MaxStyle must be of the same type");
            switch (MinStyle.GetType().FullName)
            {
                case "SharpMap.Styles.VectorStyle":
                    return CalculateVectorStyle(MinStyle as VectorStyle, MaxStyle as VectorStyle, attr);
                case "SharpMap.Styles.LabelStyle":
                    return CalculateLabelStyle(MinStyle as LabelStyle, MaxStyle as LabelStyle, attr);
                default:
                    throw new ArgumentException("Only SharpMap.Styles.VectorStyle and SharpMap.Styles.LabelStyle are supported for the gradient theme");
            }
        }

Usage Example

示例#1
0
        public void GetStyleForNoDataValue()
        {
            var minVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Red) };
            var maxVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Blue) };
            var theme = new GradientTheme("red to blue", 10.0, 100.123, minVectorStyle, maxVectorStyle, null, null, null)
                {
                    NoDataValues = new List<double> {12.3}
                };

            var result = (VectorStyle)theme.GetStyle(10.0);
            AssertColor(Color.Red, ((SolidBrush)result.Fill).Color); // Expecting SolidBrush
            AssertColor(Color.FromArgb(255, 138,43, 226), result.Line.Color);

            result = (VectorStyle)theme.GetStyle(12.3);
            AssertColor(Color.Transparent, ((SolidBrush)result.Fill).Color); // Expecting SolidBrush
            AssertColor(Color.Transparent, result.Line.Color);
        }