/// <summary> /// This attempts to increase the numeric index, which will cause it to be drawn later, /// or higher up on the cue, which means it will be drawn AFTER the previous layers, /// and therefore is a higher priority. If the category does not exist in the collection /// or the category is already at the highest value, this returns false. /// </summary> /// <param name="category">The category to promote if possible.</param> /// <returns>Boolean, true if the promotion was successful</returns> public bool Promote(ILabelCategory category) { if (category == null) { return(false); } if (Categories == null) { return(false); } if (Categories.Count == 0) { return(false); } if (Categories.Contains(category) == false) { return(false); } int index = Categories.IndexOf(category); if (index == Categories.Count - 1) { return(false); } index += 1; Categories.Remove(category); Categories.Insert(index, category); return(true); }
/// <summary> /// Draws a label on a point with various different methods. /// </summary> /// <param name="e">The map args.</param> /// <param name="g">Graphics object used for drawing.</param> /// <param name="f">Feature whose label gets drawn.</param> /// <param name="category">The label category the feature belongs to.</param> /// <param name="selected">Indicates whether the feature is selected.</param> /// <param name="existingLabels">List with the already existing labels.</param> public static void DrawPointFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels) { var symb = selected ? category.SelectionSymbolizer : category.Symbolizer; // Gets the features text and calculate the label size string txt = category.CalculateExpression(f.DataRow, selected, f.Fid); if (txt == null) { return; } var angle = GetAngleToRotate(symb, f); Func <SizeF> labelSize = () => g.MeasureString(txt, CacheList.GetFont(symb)); // Depending on the labeling strategy we do different things if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts) { for (int n = 0; n < f.Geometry.NumGeometries; n++) { RectangleF labelBounds = PlacePointLabel(f.Geometry.GetGeometryN(n), e, labelSize, symb, angle); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle); } } else { RectangleF labelBounds = PlacePointLabel(f.Geometry, e, labelSize, symb, angle); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle); } }
public FormRenameCat(ILabelCategory lc, IList <ILabelCategory> ListCats) { InitializeComponent(); _lc = lc; _ListCats = ListCats; textBoxName.Text = _lc.Name; }
/// <summary> /// Draws a label on a point with various different methods /// </summary> /// <param name="e"></param> /// <param name="g"></param> /// <param name="f"></param> /// <param name="category"></param> /// <param name="selected"></param> /// <param name="existingLabels"></param> public static void DrawPointFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels) { ILabelSymbolizer symb = category.Symbolizer; if (selected) { symb = category.SelectionSymbolizer; } //Gets the features text and calculate the label size string txt = GetLabelText(f, category); if (txt == null) { return; } Func <SizeF> labelSize = () => g.MeasureString(txt, _caches.GetFont(symb)); //Depending on the labeling strategy we do diff things if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts) { for (int n = 0; n < f.NumGeometries; n++) { RectangleF labelBounds = PlacePointLabel(f, e, labelSize, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } } else { RectangleF labelBounds = PlacePointLabel(f, e, labelSize, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } }
/// <summary> /// Draws a label on a line with various different methods. /// </summary> /// <param name="e">The map args.</param> /// <param name="g">Graphics object used for drawing.</param> /// <param name="f">Feature whose label gets drawn.</param> /// <param name="category">The label category the feature belongs to.</param> /// <param name="selected">Indicates whether the feature is selected.</param> /// <param name="existingLabels">List with the already existing labels.</param> public static void DrawLineFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels) { var symb = selected ? category.SelectionSymbolizer : category.Symbolizer; // Gets the features text and calculate the label size string txt = category.CalculateExpression(f.DataRow, selected, f.Fid); if (txt == null) { return; } Func <SizeF> labelSize = () => g.MeasureString(txt, CacheList.GetFont(symb)); IGeometry geo = f.Geometry; if (geo.NumGeometries == 1) { var angle = GetAngleToRotate(symb, f, f.Geometry); RectangleF labelBounds = PlaceLineLabel(f.Geometry, labelSize, e, symb, angle); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle); } else { // Depending on the labeling strategy we do diff things if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts) { for (int n = 0; n < geo.NumGeometries; n++) { var angle = GetAngleToRotate(symb, f, geo.GetGeometryN(n)); RectangleF labelBounds = PlaceLineLabel(geo.GetGeometryN(n), labelSize, e, symb, angle); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle); } } else { double longestLine = 0; int longestIndex = 0; for (int n = 0; n < geo.NumGeometries; n++) { ILineString ls = geo.GetGeometryN(n) as ILineString; double tempLength = 0; if (ls != null) { tempLength = ls.Length; } if (longestLine < tempLength) { longestLine = tempLength; longestIndex = n; } } var angle = GetAngleToRotate(symb, f, geo.GetGeometryN(longestIndex)); RectangleF labelBounds = PlaceLineLabel(geo.GetGeometryN(longestIndex), labelSize, e, symb, angle); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle); } } }
/// <summary> /// Draws a label on a polygon with various different methods /// </summary> /// <param name="e"></param> /// <param name="g"></param> /// <param name="f"></param> /// <param name="category"></param> /// <param name="selected"></param> /// <param name="existingLabels"></param> public static void DrawPolygonFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels) { ILabelSymbolizer symb = category.Symbolizer; if (selected) { symb = category.SelectionSymbolizer; } //Gets the features text and calculate the label size string txt = GetLabelText(f, category); if (txt == null) { return; } SizeF labelSize = g.MeasureString(txt, symb.GetFont()); if (f.NumGeometries == 1) { RectangleF labelBounds = PlacePolygonLabel(f.BasicGeometry, e, labelSize, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } else { if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts) { for (int n = 0; n < f.NumGeometries; n++) { RectangleF labelBounds = PlacePolygonLabel(f.GetBasicGeometryN(n), e, labelSize, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } } else { double largestArea = 0; IPolygon largest = null; for (int n = 0; n < f.NumGeometries; n++) { IPolygon pg = Geometry.FromBasicGeometry(f.GetBasicGeometryN(n)) as IPolygon; if (pg == null) { continue; } double tempArea = pg.Area; if (largestArea < tempArea) { largestArea = tempArea; largest = pg; } } RectangleF labelBounds = PlacePolygonLabel(largest, e, labelSize, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } } //Depending on the labeling strategy we do diff things }
/// <summary> /// Draws a label on a polygon with various different methods /// </summary> /// <param name="e">The map args.</param> /// <param name="g">Graphics object used for drawing.</param> /// <param name="f">Feature whose label gets drawn.</param> /// <param name="category">The label category the feature belongs to.</param> /// <param name="selected">Indicates whether the feature is selected.</param> /// <param name="existingLabels">List with the already existing labels.</param> public static void DrawPolygonFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels) { var symb = selected ? category.SelectionSymbolizer : category.Symbolizer; // Gets the features text and calculate the label size string txt = category.CalculateExpression(f.DataRow, selected, f.Fid); if (txt == null) { return; } var angle = GetAngleToRotate(symb, f); Func <SizeF> labelSize = () => g.MeasureString(txt, CacheList.GetFont(symb)); IGeometry geo = f.Geometry; if (geo.NumGeometries == 1) { RectangleF labelBounds = PlacePolygonLabel(f.Geometry, e, labelSize, symb, angle); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle); } else { if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts) { for (int n = 0; n < geo.NumGeometries; n++) { RectangleF labelBounds = PlacePolygonLabel(geo.GetGeometryN(n), e, labelSize, symb, angle); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle); } } else { double largestArea = 0; IPolygon largest = null; for (int n = 0; n < geo.NumGeometries; n++) { IPolygon pg = geo.GetGeometryN(n) as IPolygon; if (pg == null) { continue; } double tempArea = pg.Area; if (largestArea < tempArea) { largestArea = tempArea; largest = pg; } } RectangleF labelBounds = PlacePolygonLabel(largest, e, labelSize, symb, angle); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle); } } }
/// <summary> /// Draws a label on a line with various different methods /// </summary> public static void DrawLineFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels) { var symb = selected? category.SelectionSymbolizer : category.Symbolizer; //Gets the features text and calculate the label size string txt = GetLabelText(f, category, symb); if (txt == null) { return; } Func <SizeF> labelSize = () => g.MeasureString(txt, _caches.GetFont(symb)); if (f.NumGeometries == 1) { RectangleF labelBounds = PlaceLineLabel(f.BasicGeometry, labelSize, e, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } else { //Depending on the labeling strategy we do diff things if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts) { for (int n = 0; n < f.NumGeometries; n++) { RectangleF labelBounds = PlaceLineLabel(f.GetBasicGeometryN(n), labelSize, e, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } } else { double longestLine = 0; int longestIndex = 0; for (int n = 0; n < f.NumGeometries; n++) { ILineString ls = f.GetBasicGeometryN(n) as ILineString; double tempLength = 0; if (ls != null) { tempLength = ls.Length; } if (longestLine < tempLength) { longestLine = tempLength; longestIndex = n; } } RectangleF labelBounds = PlaceLineLabel(f.GetBasicGeometryN(longestIndex), labelSize, e, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } } }
private static string GetLabelText(IFeature feature, ILabelCategory category) { string result = category.Expression; if (result != null && feature != null) { foreach (DataColumn dc in feature.DataRow.Table.Columns) { result = result.Replace("[" + dc.ColumnName + "]", feature.DataRow[dc.ColumnName].ToString()); } } return(result); }
public void ConvertLayerProperties_MapDataWithMetaAndSelectedMetaDataAttributeInDataColumns_CustomLabelLayerSetToLayer() { // Setup var testConverter = new TestFeatureBasedMapDataConverter(); var mapData = new TestFeatureBasedMapData("test data") { Features = new[] { new MapFeature(Enumerable.Empty <MapGeometry>()) { MetaData = { { "Id", 1.1 }, { "Name", "Feature" } } } }, SelectedMetaDataAttribute = "Name" }; var mapLayer = new TestFeatureLayer { DataSet = { DataTable = { Columns = { "1", "2" } } } }; // Call testConverter.ConvertLayerProperties(mapData, mapLayer); // Assert Assert.IsNotNull(mapLayer.LabelLayer); ILabelCategory labelCategory = mapLayer.LabelLayer.Symbology.Categories[0]; Assert.AreEqual("FID", labelCategory.Symbolizer.PriorityField); Assert.AreEqual(ContentAlignment.MiddleRight, labelCategory.Symbolizer.Orientation); Assert.AreEqual(5, labelCategory.Symbolizer.OffsetX); Assert.AreEqual("[2]", labelCategory.Expression); }
private static string GetLabelText(IFeature feature, ILabelCategory category) { string result = category.Expression; if (!string.IsNullOrEmpty(result) && feature != null) { foreach (DataColumn dc in feature.DataRow.Table.Columns) { if (String.IsNullOrEmpty(result)) { break; // Result already is empty, no need to iterate over columns } result = result.Replace("[" + dc.ColumnName + "]", feature.DataRow[dc.ColumnName].ToString()); } } return(result); }
//============================================================================= #region Methods /// <summary> /// /// </summary> public void initControl(ILabelCategory iLabelCat) { cb_UseMask.Checked = false; groupBox_Layers.Enabled = false; groupBox_Margins.Enabled = false; tv_layers.Nodes.Clear(); _l_SelectedItems = new List <TreeNode>(); updateTable(); if (iLabelCat != null) { cb_UseMask.Checked = iLabelCat.UseMask; doubleBox_TopMargin.Value = iLabelCat.MaskMargin_Top; doubleBox_BottomMargin.Value = iLabelCat.MaskMargin_Bottom; doubleBox_LeftMargin.Value = iLabelCat.MaskMargin_Left; doubleBox_RightMargin.Value = iLabelCat.MaskMargin_Right; checkNode(iLabelCat.MaskedLayers); } }
/// <summary> /// Draws a label on a point with various different methods. /// </summary> /// <param name="e">The map args.</param> /// <param name="g">Graphics object used for drawing.</param> /// <param name="f">Feature whose label gets drawn.</param> /// <param name="category">The label category the feature belongs to.</param> /// <param name="selected">Indicates whether the feature is selected.</param> /// <param name="existingLabels">List with the already existing labels.</param> public static void DrawPointFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels) { var symb = selected ? category.SelectionSymbolizer : category.Symbolizer; // CGX ILabelSymbolizer symb2 = symb.Clone() as ILabelSymbolizer; double scaleSize = 1.0; /* IMapFrame mapf = map * if (MapFrame.ReferenceScale > 1.0) * { * double dReferenceScale = (MapFrame as IMapFrame).ReferenceScale; * double dCurrentScale = (MapFrame as IMapFrame).CurrentScale; * scaleSize = dReferenceScale / dCurrentScale; * }*/ symb2.FontSize = symb.FontSize * Convert.ToSingle(scaleSize); // Fin CGX // Gets the features text and calculate the label size string txt = category.CalculateExpression(f.DataRow, selected, f.Fid); if (txt == null) { return; } var angle = GetAngleToRotate(symb, f); Func <SizeF> labelSize = () => g.MeasureString(txt, CacheList.GetFont(symb)); // Depending on the labeling strategy we do different things if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts) { for (int n = 0; n < f.Geometry.NumGeometries; n++) { RectangleF labelBounds = PlacePointLabel(f.Geometry.GetGeometryN(n), e, labelSize, symb, angle); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle); } } else { RectangleF labelBounds = PlacePointLabel(f.Geometry, e, labelSize, symb, angle); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle); } }
/// <summary> /// Attempts to reduce the integer index representing this categories rank in the /// list. By doing this, it will be drawn sooner, and therefore subsequent /// layers will be drawn on top of this layer, and so it reduces the categories /// priority. If this collection does not contain the category or it is already /// at index 0, this will return false. /// </summary> /// <param name="category">The ILabelCategory to demote.</param> /// <returns>Boolean, true if the demotion was successful.</returns> public bool Demote(ILabelCategory category) { if (category == null || Categories == null || Categories.Count == 0 || !Categories.Contains(category)) { return(false); } int index = Categories.IndexOf(category); if (index == 0) { return(false); } index -= 1; Categories.Remove(category); Categories.Insert(index, category); return(true); }
/// <summary> /// Draws a label on a polygon with various different methods /// </summary> /// <param name="e"></param> /// <param name="g"></param> /// <param name="f"></param> /// <param name="category"></param> /// <param name="selected"></param> /// <param name="existingLabels"></param> public static void DrawPolygonFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List<RectangleF> existingLabels) { ILabelSymbolizer symb = category.Symbolizer; if (selected) symb = category.SelectionSymbolizer; //Gets the features text and calculate the label size string txt = GetLabelText(f, category); if (txt == null) return; SizeF labelSize = g.MeasureString(txt, symb.GetFont()); if (f.NumGeometries == 1) { RectangleF labelBounds = PlacePolygonLabel(f.BasicGeometry, e, labelSize, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } else { if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts) { for (int n = 0; n < f.NumGeometries; n++) { RectangleF labelBounds = PlacePolygonLabel(f.GetBasicGeometryN(n), e, labelSize, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } } else { double largestArea = 0; IPolygon largest = null; for (int n = 0; n < f.NumGeometries; n++) { IPolygon pg = Geometry.FromBasicGeometry(f.GetBasicGeometryN(n)) as IPolygon; if (pg == null) continue; double tempArea = pg.Area; if (largestArea < tempArea) { largestArea = tempArea; largest = pg; } } RectangleF labelBounds = PlacePolygonLabel(largest, e, labelSize, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } } //Depending on the labeling strategy we do diff things }
/// <summary> /// Updates the controls with the data of the selected category. /// </summary> private void lbCategories_SelectedIndexChanged(object sender, EventArgs e) { _activeCategory = (ILabelCategory)lbCategories.SelectedItem ?? new LabelCategory(); // Set fake category to avoid null checks UpdateControls(); }
private void lbCategories_SelectedIndexChanged(object sender, EventArgs e) { _activeCategory = lbCategories.SelectedItem as ILabelCategory; UpdateControls(); }
/// <summary> /// Creates a new instance of the LabelDrawState based on the specified parameters. /// </summary> /// <param name="category">The category</param> /// <param name="selected">Boolean, true if the label is selected</param> /// <param name="visible">Boolean, true if the label should be visible</param> public LabelDrawState(ILabelCategory category, bool selected, bool visible) { Category = category; Selected = selected; Visible = visible; }
/// <summary> /// Creates a new instance of the LabelDrawState class where selected is false /// but visible is true. /// </summary> /// <param name="category">The category</param> public LabelDrawState(ILabelCategory category) { Category = category; Visible = true; }
/// <summary> /// Creates a new drawn state with the specified category /// </summary> /// <param name="category">The category</param> public FastLabelDrawnState(ILabelCategory category) { Category = category; }
private static string GetLabelText(IFeature feature, ILabelCategory category) { string result = category.Expression; if (result != null && feature != null) { foreach (DataColumn dc in feature.DataRow.Table.Columns) { result = result.Replace("[" + dc.ColumnName + "]", feature.DataRow[dc.ColumnName].ToString()); } } return result; }
/// <summary> /// Draws a label on a line with various different methods /// </summary> /// <param name="e"></param> /// <param name="g"></param> /// <param name="f"></param> /// <param name="category"></param> /// <param name="selected"></param> /// <param name="existingLabels"></param> public static void DrawLineFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List<RectangleF> existingLabels) { if (f == null) return; ILabelSymbolizer symb = category.Symbolizer; if (selected) symb = category.SelectionSymbolizer; //Gets the features text and calculate the label size string txt = GetLabelText(f, category); if (txt == null) return; SizeF labelSize = g.MeasureString(txt, symb.GetFont()); if (f.NumGeometries == 1) { RectangleF labelBounds = PlaceLineLabel(f.BasicGeometry, labelSize, e, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } else { //Depending on the labeling strategy we do diff things if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts) { for (int n = 0; n < f.NumGeometries; n++) { RectangleF labelBounds = PlaceLineLabel(f.GetBasicGeometryN(n), labelSize, e, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } } else { double longestLine = 0; int longestIndex = 0; for (int n = 0; n < f.NumGeometries; n++) { ILineString ls = f.GetBasicGeometryN(n) as ILineString; double tempLength = 0; if (ls != null) tempLength = ls.Length; if (longestLine < tempLength) { longestLine = tempLength; longestIndex = n; } } RectangleF labelBounds = PlaceLineLabel(f.GetBasicGeometryN(longestIndex), labelSize, e, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } } }
private static string GetLabelText(IFeature feature, ILabelCategory category, ILabelSymbolizer symb) { // Function which checks that text contains any expression var exprCheck = (Func <string, bool>) delegate(string inStr) { if (String.IsNullOrEmpty(inStr)) { return(false); } const char symb1 = ']'; const char symb2 = '['; bool s1 = false, s2 = false; foreach (var t in inStr) { if (t == symb1) { s1 = true; if (s1 && s2) { return(true); } } else if (t == symb2) { s2 = true; if (s1 && s2) { return(true); } } } return(false); }; var useFloatingFormat = !string.IsNullOrWhiteSpace(symb.FloatingFormat); var result = category.Expression; if (feature != null && exprCheck(result)) { foreach (DataColumn dc in feature.DataRow.Table.Columns) { var curColumnReplacement = "[" + dc.ColumnName + "]"; // Check that this column used in expression if (!result.Contains(curColumnReplacement)) { continue; } var currValue = feature.DataRow[dc.ColumnName]; if (useFloatingFormat && (dc.DataType == typeof(double) || dc.DataType == typeof(float))) { try { var dv = Convert.ToDouble(currValue); currValue = dv.ToString(symb.FloatingFormat); } catch (Exception) { currValue = SafeToString(currValue); } } else { currValue = SafeToString(currValue); } result = result.Replace(curColumnReplacement, (string)currValue); if (!exprCheck(result)) { break; // result string does not contains any expressions, no need to iterate over columns } } } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="FastLabelDrawnState"/> class. /// </summary> /// <param name="category">The category.</param> public FastLabelDrawnState(ILabelCategory category) { Category = category; }
/// <summary> /// This attempts to increase the numeric index, which will cause it to be drawn later, /// or higher up on the cue, which means it will be drawn AFTER the previous layers, /// and therefore is a higher priority. If the category does not exist in the collection /// or the category is already at the highest value, this returns false. /// </summary> /// <param name="category">The category to promote if possible.</param> /// <returns>Boolean, true if the promotion was successful</returns> public bool Promote(ILabelCategory category) { if (category == null) return false; if (Categories == null) return false; if (Categories.Count == 0) return false; if (Categories.Contains(category) == false) return false; int index = Categories.IndexOf(category); if (index == Categories.Count - 1) return false; index += 1; Categories.Remove(category); Categories.Insert(index, category); return true; }
public FeatureSet DrawLine() { FeatureSet lineF = new FeatureSet(FeatureType.Line); lineF.Projection = map.Projection; lineF.DataTable.Columns.Add("Value", typeof(double));//方便之后在等值线上标注 MapLineLayer lineLayer = default(MapLineLayer); lineLayer = (MapLineLayer)map.Layers.Add(lineF); LineSymbolizer symnol = new LineSymbolizer(Color.Black, 2); lineLayer.Symbolizer = symnol; string[] thename = raster.Filename.Split('\\'); lineLayer.LegendText = thename[thename.Length - 1] + "_line"; //MapLabelLayer MapLabelLayer labelLayer = new MapLabelLayer(); ILabelCategory category = labelLayer.Symbology.Categories[0]; category.Expression = "[Value]"; category.SelectionSymbolizer.BackColorEnabled = true; category.Symbolizer.BorderVisible = false; category.Symbolizer.BackColor = Color.FromArgb(128, Color.LightBlue);; category.Symbolizer.FontStyle = FontStyle.Regular; category.Symbolizer.FontColor = Color.Black; category.Symbolizer.FontSize = 8.5f; category.Symbolizer.Orientation = ContentAlignment.MiddleCenter; category.Symbolizer.Alignment = StringAlignment.Center; lineLayer.ShowLabels = true; lineLayer.LabelLayer = labelLayer; /*double min_X, min_Y, max_X, max_Y; * min_X = raster.Xllcenter - raster.CellWidth / 2; * min_Y = raster.Yllcenter - raster.CellHeight / 2; * max_X = raster.CellToProj(0, raster.NumColumns-1).X + raster.CellWidth / 2; * max_Y = raster.CellToProj(0, 0).Y + raster.CellHeight/2; * double interspace = (raster.CellToProj(1, 1).X - raster.CellToProj(0, 0).X) * * (raster.CellToProj(1, 1).X - raster.CellToProj(0, 0).X) + (raster.CellToProj(1, 1).Y - raster.CellToProj(0, 0).Y) * * (raster.CellToProj(1, 1).Y - raster.CellToProj(0, 0).Y); * Console.WriteLine("minX: " + min_X + " , minY: "+ min_Y + " , maxX: " + max_X + " , maxY: " + max_Y);*/ List <Tin_Point> lpoints = new List <Tin_Point>(); foreach (var lines in contourData) { //if(lines.Key == 18) //{ //int i = 0; foreach (var line in lines.Value) { Tin_Point p1 = new Tin_Point(line.startPoint.X, line.startPoint.Y, lines.Key); Tin_Point p2 = new Tin_Point(line.endPoint.X, line.endPoint.Y, lines.Key); //p1.Type = i; //p2.Type = i; lpoints.Add(p1); lpoints.Add(p2); List <Coordinate> lineArray = new List <Coordinate>(); LineString lineGeometry = new LineString(lineArray); IFeature lineFeature = lineF.AddFeature(lineGeometry); lineFeature.Coordinates.Add(line.startPoint); lineFeature.Coordinates.Add(line.endPoint); lineFeature.DataRow["Value"] = lines.Key; lineF.InitializeVertices(); //i++; } //} } /* * Polish polish = new Polish(); * List<List<Tin_Point>> new_tin_points = polish.ClassifyLine(lpoints); * Console.WriteLine("new_tin_point num: " + new_tin_points.Count); * foreach(var lines in new_tin_points) * { * //int i = 0; * foreach(var p in lines) * { * Console.Write(p.X + " , " + p.Y + "||"); * } * Console.WriteLine("*********************************"); * } * foreach (var lines in new_tin_points) * { * //int i = 0; * * Console.WriteLine(lines[0].X + " , " + lines[0].Y + "||" + lines[lines.Count-1].X + " , " + lines[lines.Count - 1].Y); * } * * * foreach (var freeline in new_tin_points) * { * List<Coordinate> lineArray = new List<Coordinate>(); ; * ILineString lineGeometry = new LineString(lineArray); * IFeature lineFeature = lineF.AddFeature(lineGeometry); * lineFeature.DataRow["Value"] = (int)freeline[0].Value; * foreach (var p in freeline) * { * Coordinate coordinate = new Coordinate(p.X, p.Y); * lineArray.Add(coordinate); * lineFeature.Coordinates.Add(coordinate); * lineF.InitializeVertices(); * } * } */ map.ResetBuffer(); return(lineF); }
/// <summary> /// Draws a label on a point with various different methods /// </summary> /// <param name="e"></param> /// <param name="g"></param> /// <param name="f"></param> /// <param name="category"></param> /// <param name="selected"></param> /// <param name="existingLabels"></param> public static void DrawPointFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List<RectangleF> existingLabels) { ILabelSymbolizer symb = category.Symbolizer; if (selected) symb = category.SelectionSymbolizer; //Gets the features text and calculate the label size string txt = GetLabelText(f, category); if (txt == null) return; SizeF labelSize = g.MeasureString(txt, symb.GetFont()); //Depending on the labeling strategy we do diff things if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts) { for (int n = 0; n < f.NumGeometries; n++) { RectangleF labelBounds = PlacePointLabel(f, e, labelSize, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } } else { RectangleF labelBounds = PlacePointLabel(f, e, labelSize, symb); CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels); } }