private void menu_Click(object sender, EventArgs e) { FormContour Frm = new FormContour(); Frm.layers = App.Map.GetRasterLayers(); if (Frm.layers.GetLength(0) <= 0) { MessageBox.Show("No raster layer found!"); return; } if (Frm.ShowDialog() == DialogResult.OK) { IMapFeatureLayer fl = App.Map.Layers.Add(Frm.Contours); fl.LegendText = Frm.LayerName + " - Contours"; int numlevs = Frm.lev.GetLength(0); switch (Frm.contourtype) { case (Contour.ContourType.Line): { LineScheme ls = new LineScheme(); ls.Categories.Clear(); for (int i = 0; i < Frm.color.GetLength(0); i++) { LineCategory lc = new LineCategory(Frm.color[i], 2.0); lc.FilterExpression = "[Value] = " + Frm.lev[i].ToString(); lc.LegendText = Frm.lev[i].ToString(); ls.AddCategory(lc); } fl.Symbology = ls; } break; case (Contour.ContourType.Polygon): { PolygonScheme ps = new PolygonScheme(); ps.Categories.Clear(); for (int i = 0; i < Frm.color.GetLength(0); i++) { PolygonCategory pc = new PolygonCategory(Frm.color[i], Color.Transparent, 0); pc.FilterExpression = "[Lev] = " + i.ToString(); pc.LegendText = Frm.lev[i].ToString() + " - " + Frm.lev[i + 1].ToString(); ps.AddCategory(pc); } fl.Symbology = ps; } break; } } }
/// <summary> /// Creates a new instance of PointScheme with no categories added to the list yet. /// </summary> public LineScheme() { Configure(); LineCategory def = new LineCategory(); Categories.Add(def); }
/// <summary> /// Uses the settings on this scheme to create a random category. /// </summary> /// <returns>A new IFeatureCategory</returns> public override IFeatureCategory CreateRandomCategory(string filterExpression) { LineCategory result = new LineCategory(); Color fillColor = CreateRandomColor(); result.Symbolizer = new LineSymbolizer(fillColor, 2); result.FilterExpression = filterExpression; result.LegendText = filterExpression; return(result); }
/// <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(); } LineCategory cat = new LineCategory(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> /// 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(); } LineCategory cat = new LineCategory(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> /// Uses the settings on this scheme to create a random category. /// </summary> /// <returns>A new IFeatureCategory</returns> public override IFeatureCategory CreateRandomCategory(string filterExpression) { LineCategory result = new LineCategory(); Color fillColor = CreateRandomColor(); result.Symbolizer = new LineSymbolizer(fillColor, 2); result.FilterExpression = filterExpression; result.LegendText = filterExpression; return result; }