/// <summary> /// Returns the style based on a numeric DataColumn, where style /// properties are linearly interpolated between max and min values. /// </summary> /// <param name="row">Feature</param> /// <returns><see cref="SharpMap.Styles.IStyle">Style</see> calculated by a linear interpolation between the min/max styles</returns> public virtual IStyle GetStyle(FeatureDataRow row) { double attr; try { attr = GetAttributeValue(row); } 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"); } }
/// <summary> /// Returns the style based on a numeric DataColumn, where style /// properties are linearly interpolated between max and min values. /// </summary> /// <param name="row">Feature</param> /// <returns><see cref="Mapsui.Styles.IStyle">Style</see> calculated by a linear interpolation between the min/max styles</returns> public IStyle GetStyle(IFeature row) { double attr; try { attr = Convert.ToDouble(row[ColumnName.ToUpper()]); } catch { throw new Exception("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"); } var style = (IStyle)Activator.CreateInstance(MinStyle.GetType()); if (MinStyle is LabelStyle && MaxStyle is LabelStyle) { CalculateLabelStyle(style as LabelStyle, MinStyle as LabelStyle, MaxStyle as LabelStyle, attr); } if (MinStyle is VectorStyle && MaxStyle is VectorStyle) { CalculateVectorStyle(style as VectorStyle, MinStyle as VectorStyle, MaxStyle as VectorStyle, attr); } if (MinStyle is SymbolStyle && MaxStyle is SymbolStyle) { CalculateSymbolStyle(style as SymbolStyle, MinStyle as SymbolStyle, MaxStyle as SymbolStyle, attr); } return(style); }
/// <summary> /// Returns the style based on a numeric DataColumn, where style /// properties are linearly interpolated between max and min values. /// </summary> /// <param name="feature">Feature</param> /// <returns><see cref="IStyle">Style</see> calculated by a linear interpolation between the min/max styles</returns> public override IStyle GetStyle(IFeature feature) { double attr; try { attr = FeatureAttributeAccessorHelper.GetAttributeValue <double>(feature, AttributeName); } 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(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"); } }
/// <summary> /// Returns the style based on a numeric DataColumn, where style /// properties are linearly interpolated between max and min values. /// </summary> /// <param name="row">Feature</param> /// <returns><see cref="SharpMap.Styles.IStyle">Style</see> calculated by a linear interpolation between the min/max styles</returns> public IStyle GetStyle(FeatureDataRow row) { Double weighting; try { weighting = Convert.ToDouble(row[_columnName]); } catch { throw new InvalidOperationException( "Invalid attribute type in gradient theme. " + "Couldn't parse weighting attribute (must be numeric)."); } if (MinStyle == null) { throw new InvalidOperationException("Cannot create a gradient style if the MinStyle is missing."); } if (MaxStyle == null) { throw new InvalidOperationException("Cannot create a gradient style if the MaxStyle is missing."); } Type minStyleType = MinStyle.GetType(); Type maxStyleType = MaxStyle.GetType(); if (minStyleType != maxStyleType) { throw new ArgumentException("MinStyle and MaxStyle must be of the same type"); } CalculateStyleDelegate styleCalculator; _styleTypeFunctionTable.TryGetValue(minStyleType.TypeHandle, out styleCalculator); if (styleCalculator == null) { throw new ArgumentException( "Only SharpMap.Styles.VectorStyle and SharpMap.Styles.LabelStyle " + "are supported for the gradient theme"); } return(styleCalculator(MinStyle, MaxStyle, weighting)); }
public override object Clone() { var gradientTheme = new GradientTheme(attributeName, minValue, maxValue, (IStyle)MinStyle.Clone(), (IStyle)MaxStyle.Clone(), (null != FillColorBlend) ? (ColorBlend)FillColorBlend.Clone() : null, (null != LineColorBlend) ? (ColorBlend)LineColorBlend.Clone() : null, (null != TextColorBlend) ? (ColorBlend)TextColorBlend.Clone() : null, numberOfClasses); gradientTheme.ThemeItems.Clear(); foreach (var themeItem in ThemeItems) { gradientTheme.ThemeItems.Add((IThemeItem)((GradientThemeItem)themeItem).Clone()); } if (NoDataValues != null) { gradientTheme.NoDataValues = NoDataValues.Cast <object>().ToArray(); } return(gradientTheme); }