/// <summary> /// Calculates the unique colors as a scheme /// </summary> /// <param name="fs">The featureset with the data Table definition</param> /// <param name="uniqueField">The unique field</param> public Hashtable GenerateUniqueColors(IFeatureSet fs, string uniqueField) { Hashtable result = new Hashtable(); // a hashtable of colors DataTable dt = fs.DataTable; ArrayList vals = new ArrayList(); int i = 0; foreach (DataRow row in dt.Rows) { if (uniqueField != "FID") { if (vals.Contains(row[uniqueField]) == false) { vals.Add(row[uniqueField]); } } else { vals.Add(i); i++; } } Random rnd = new Random(); foreach (object item in vals) { Color c = rnd.NextColor(); while(result.ContainsKey(c)) { c = rnd.NextColor(); } PolygonCategory cat = new PolygonCategory(c, c, 1); string flt = "[" + uniqueField + "] = "; if (uniqueField == "FID") { flt += item; } else { if (dt.Columns[uniqueField].DataType == typeof(string)) { flt += "'" + item + "'"; } else { flt += item.ToString(); } } cat.FilterExpression = flt; Categories.Add(cat); result.Add(c, item); } return result; }
/// <summary> /// Creates the category using a random fill color /// </summary> /// <param name="fillColor">The base color to use for creating the category</param> /// <param name="size">This is ignored for polygons</param> /// <returns>A new polygon category</returns> public override ICategory CreateNewCategory(Color fillColor, double size) { PolygonCategory result = new PolygonCategory(); if (EditorSettings.UseGradient) { result.Symbolizer = new PolygonSymbolizer(fillColor.Lighter(.2f), fillColor.Darker(.2f), EditorSettings.GradientAngle, GradientTypes.Linear, fillColor.Darker(.5f), 1); } else { if(EditorSettings.TemplateSymbolizer != null) { result.Symbolizer = EditorSettings.TemplateSymbolizer.Copy() as IPolygonSymbolizer; result.SetColor(fillColor); } else { result.Symbolizer = new PolygonSymbolizer(fillColor, fillColor.Darker(.5f)); } } return result; }
/// <summary> /// Uses the settings on this scheme to create a random category. /// </summary> /// <returns>A new IFeatureCategory</returns> public override IFeatureCategory CreateRandomCategory(string filterExpression) { PolygonCategory result = new PolygonCategory(); Color fillColor = CreateRandomColor(); if (EditorSettings.UseGradient) { result.Symbolizer = new PolygonSymbolizer(fillColor.Lighter(.2f), fillColor.Darker(.2f), EditorSettings.GradientAngle, GradientTypes.Linear, fillColor.Darker(.5f), 1); } else { result.Symbolizer = new PolygonSymbolizer(fillColor, fillColor.Darker(.5f)); } result.FilterExpression = filterExpression; result.LegendText = filterExpression; return result; }
/// <summary> /// creates a new instance of the PointScheme, but assigns the specified symbolizer /// as the symbolizer to use on a single default category. /// </summary> /// <param name="extent">The geographic point size for the default will be 1/100th the specified extent</param> public PolygonScheme(IEnvelope extent) { Configure(); PolygonCategory def = new PolygonCategory(extent); Categories.Add(def); }