private void Configure() { _categories = new PolygonCategoryCollection(); OnIncludeCategories(_categories); PolygonCategory def = new PolygonCategory(); _categories.Add(def); }
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> /// 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> /// 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, GradientType.Linear, fillColor.Darker(.5f), 1); } else { result.Symbolizer = new PolygonSymbolizer(fillColor, fillColor.Darker(.5f)); } result.FilterExpression = filterExpression; result.LegendText = filterExpression; 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, GradientType.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> /// Deserializes the layer. /// </summary> /// <param name="layer">The layer.</param> /// <param name="polyLayer">The poly layer.</param> internal static void DeserializeLayer(dynamic layer, MapPolygonLayer polyLayer) { if (UseAlternateParser(layer)) { DeserializeLayerAlternateVersion(layer.ShapefileProperties, polyLayer); return; } var polySymbolizer = new PolygonSymbolizer(); var outlineColor = LegacyDeserializer.GetColor(layer.ShapeFileProperties["OutLineColor"]); var outlineWidth = Convert.ToDouble(layer.ShapeFileProperties["LineOrPointSize"]); polySymbolizer.SetOutline(outlineColor, outlineWidth); if (Convert.ToBoolean(layer.ShapeFileProperties["DrawFill"])) { Color color = LegacyDeserializer.GetColor(layer.ShapeFileProperties["Color"]); float transparency = Convert.ToSingle(layer.ShapeFileProperties["TransparencyPercent"]); color = color.ToTransparent(transparency); polySymbolizer.SetFillColor(color); } else { polySymbolizer.SetFillColor(Color.Transparent); } polyLayer.Symbolizer = polySymbolizer; try { int fieldIndex = Convert.ToInt32(layer.ShapeFileProperties.Legend["FieldIndex"]); // we have to clear the categories or the collection ends up with a default item polyLayer.Symbology.Categories.Clear(); foreach (var colorBreak in layer.ShapeFileProperties.Legend.ColorBreaks.Elements()) { PolygonCategory category; string startValue = colorBreak["StartValue"]; string endValue = colorBreak["EndValue"]; if (startValue == endValue) { category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["StartColor"]), 0); category.FilterExpression = String.Format("[{0}] = '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue); category.LegendText = startValue; } else { category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["EndColor"]), 0, GradientType.Linear, outlineColor, outlineWidth); category.FilterExpression = String.Format("'{2}' >= [{0}] >= '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue, endValue); category.LegendText = String.Format("{0} - {1}", startValue, endValue); } category.LegendText = startValue; category.LegendItemVisible = Convert.ToBoolean(colorBreak["Visible"]); polyLayer.Symbology.AddCategory(category); } // it took too a lot of work to figure out that we would need to do this... polyLayer.ApplyScheme(polyLayer.Symbology); } catch (RuntimeBinderException) { // ignore and continue. // this means the legend is not available. } }
/// <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> /// 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, GradientType.Linear, fillColor.Darker(.5f), 1); } else { result.Symbolizer = new PolygonSymbolizer(fillColor, fillColor.Darker(.5f)); } result.FilterExpression = filterExpression; result.LegendText = filterExpression; 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, GradientType.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; }
private void AssociateToGrid() { IFeatureSet fT = null; IMapPolygonLayer tem = null; foreach (IMapPolygonLayer ila in this.map.GetPolygonLayers()) { fT = (IFeatureSet)ila.DataSet; tem = ila; if (ila.LegendText == "Grid") break; } if (fT == null) return; Stat stat = new Stat(false); foreach (IFeature fea in fT.Features) { IFeature center = fea.Centroid(); double st = dataK.Interpolate(center.Coordinates[0].X, center.Coordinates[0].Y, center.Coordinates[0].Z, true)[0]; fea.DataRow["Field"] = st; stat += new Stat(st); } fT.Save(); tem.DataSet.FillAttributes(); PolygonScheme polScheme = new PolygonScheme(); polScheme.EditorSettings.FieldName = "Field"; polScheme.EditorSettings.ClassificationType = ClassificationType.Custom; // polScheme.EditorSettings.StartColor = Color.Green; // polScheme.EditorSettings.EndColor = Color.Magenta; //// polScheme.EditorSettings.UseColorRange = true; // polScheme.EditorSettings.RampColors = true; for (int i = 0; i < 12; i++) { PolygonCategory cat = new PolygonCategory(); cat.SetColor(Color.FromArgb(i * 20, 50, 250 - (i * 20))); cat.Range = new Range(stat.Min + (i - 1) * (stat.Max - stat.Min) / 10, stat.Min + (i) * (stat.Max - stat.Min) / 10); cat.FilterExpression = string.Format("[Field]>{0} AND [Field]<={1}", Math.Round((double)cat.Range.Minimum, 3), Math.Round((double)cat.Range.Maximum, 3)); cat.LegendText = string.Format("{0} - {1}", Math.Round((double)cat.Range.Minimum, 3), Math.Round((double)cat.Range.Maximum, 3)); polScheme.AddCategory(cat); } tem.Symbology = polScheme; // tem.ApplyScheme(polScheme); map.ResetBuffer(); }