private void PrintLayer(IMapLayer layer, MapArgs args) { MapLabelLayer.ClearAllExistingLabels(); //need to do this or labels not drawn on refresh IMapGroup group = layer as IMapGroup; if (group != null) { foreach (IMapLayer subLayer in group.Layers) { PrintLayer(subLayer, args); } } IMapLayer geoLayer = layer; if (geoLayer != null) { if (geoLayer.UseDynamicVisibility) { if (ViewExtents.Width > geoLayer.DynamicVisibilityWidth) { return; // skip the geoLayer if we are zoomed out too far. } } if (geoLayer.IsVisible == false) { return; } geoLayer.DrawRegions(args, new List <Extent> { args.GeographicExtents }); IMapFeatureLayer mfl = geoLayer as IMapFeatureLayer; if (mfl != null) { if (mfl.UseDynamicVisibility) { if (ViewExtents.Width > mfl.DynamicVisibilityWidth) { return; } } if (mfl.ShowLabels && mfl.LabelLayer != null) { if (mfl.LabelLayer.UseDynamicVisibility) { if (ViewExtents.Width > mfl.LabelLayer.DynamicVisibilityWidth) { return; } } mfl.LabelLayer.DrawRegions(args, new List <Extent> { args.GeographicExtents }); } } } }
/// <summary> /// Add map labels for fieldAttributes feature layer /// </summary> /// <param name="pFLyr">The feature layer to add labels to</param> /// <param name="pCategoryTitle">The title of the label category (not visible)</param> /// <param name="pLabelExpression">The label expression, mFeatureIndex.e. [fieldname]</param> /// <param name="pFontFamily">The font family</param> /// <param name="pFontSize"></param> /// <param name="pFontColor"></param> /// <param name="pDynVisWidth"></param> /// <param name="pUseDynVis"></param> /// <param name="pDynVisMode"></param> public static void AddLabelsForFeatureLayer( IFeatureLayer pFeatureLayer, string pCategoryTitle, string pLabelExpression, Color pFontColor = default(Color), string pFontFamily = "Arial", int pFontSize = 12, bool pUseDynVis = false, int pDynVisWidth = 2000, DynamicVisibilityMode pDynVisMode = DynamicVisibilityMode.ZoomedIn) { Color pColor = pFontColor.IsEmpty ? Color.Black : pFontColor; var mSymbolizer = GetLabelSymbolizer(pFontFamily, pFontColor, pFontSize); var mLabelCategory = GetLabelCategory(pCategoryTitle, pLabelExpression, mSymbolizer); MapLabelLayer mMapLabelLayer = new MapLabelLayer(pFeatureLayer); pFeatureLayer.LabelLayer = mMapLabelLayer; pFeatureLayer.ShowLabels = true; pFeatureLayer.LabelLayer.Symbology.Categories.Clear(); pFeatureLayer.LabelLayer.Symbology.Categories.Add(mLabelCategory); pFeatureLayer.LabelLayer.UseDynamicVisibility = pUseDynVis; pFeatureLayer.LabelLayer.DynamicVisibilityMode = pDynVisMode; pFeatureLayer.LabelLayer.DynamicVisibilityWidth = pDynVisWidth; pFeatureLayer.LabelLayer.CreateLabels(); return; }
private static MapLabelLayer GetLabelLayer(IDictionary <string, int> attributeMapping, IFeatureSet featureSet, string labelToShow) { var labelLayer = new MapLabelLayer(); if (!string.IsNullOrEmpty(labelToShow) && attributeMapping.ContainsKey(labelToShow) && featureSet.DataTable.Columns.Contains(attributeMapping[labelToShow].ToString())) { labelLayer.Symbology.Categories[0].Symbolizer = new LabelSymbolizer { Orientation = ContentAlignment.MiddleRight, OffsetX = 5 }; labelLayer.Symbology.Categories[0].Expression = string.Format(CultureInfo.CurrentCulture, "[{0}]", attributeMapping[labelToShow]); } return(labelLayer); }
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> /// Translates the style strings from the list to DotSpatial style categories and adds them to the given layer. /// </summary> /// <param name="layer">The layer the styles get added to.</param> /// <param name="styles">The style strings that should get translated.</param> public static void TranslateStyles(IMapFeatureLayer layer, IList <string> styles) { var featureType = layer.DataSet.FeatureType; switch (featureType) { case FeatureType.MultiPoint: case FeatureType.Point: { // create the scheme var scheme = new PointScheme(); scheme.Categories.Clear(); scheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues; scheme.EditorSettings.FieldName = "style"; scheme.LegendText = "Point"; // add the default category var cat = new PointCategory(Color.Black, Symbology.PointShape.Rectangle, 5) { LegendText = "default", Symbolizer = { ScaleMode = ScaleMode.Simple, Smoothing = false } }; scheme.AddCategory(cat); var labelLayer = new MapLabelLayer(); labelLayer.Symbology.Categories.Clear(); bool needsLabels = styles.Any(_ => !string.IsNullOrWhiteSpace(_) && _.StartsWith("LABEL")); foreach (var style in styles) { TranslatePointStyle(scheme, labelLayer.Symbology, style); } // assign the scheme layer.Symbology = scheme; // assign the label layer if needed if (needsLabels) { layer.LabelLayer = labelLayer; layer.ShowLabels = true; layer.LabelLayer.CreateLabels(); } layer.DataSet.UpdateExtent(); layer.DataSet.InitializeVertices(); layer.AssignFastDrawnStates(); break; } case FeatureType.Line: { // create the scheme var scheme = new LineScheme(); scheme.Categories.Clear(); scheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues; scheme.EditorSettings.FieldName = "style"; scheme.LegendText = "Line"; // add the default category var cat = new LineCategory(Color.Black, 1) { LegendText = "default", Symbolizer = { ScaleMode = ScaleMode.Simple, Smoothing = false } }; scheme.AddCategory(cat); // add the categories from the file foreach (var style in styles) { TranslateLineStyle(scheme, style); } // assign the scheme layer.Symbology = scheme; layer.DataSet.UpdateExtent(); layer.DataSet.InitializeVertices(); layer.AssignFastDrawnStates(); break; } case FeatureType.Polygon: { // create the scheme var scheme = new PolygonScheme(); scheme.Categories.Clear(); scheme.EditorSettings.ClassificationType = ClassificationType.UniqueValues; scheme.EditorSettings.FieldName = "style"; scheme.LegendText = "Polygon"; // add the default category var cat = new PolygonCategory(Color.GhostWhite, Color.Black, 1) { LegendText = "default", Symbolizer = { ScaleMode = ScaleMode.Simple, Smoothing = false } }; scheme.AddCategory(cat); // add the categories from the file foreach (var style in styles) { TranslatePolygonStyle(scheme, style); } // assign the scheme layer.Symbology = scheme; layer.DataSet.UpdateExtent(); layer.DataSet.InitializeVertices(); layer.AssignFastDrawnStates(); break; } default: throw new ArgumentOutOfRangeException(nameof(featureType), featureType, null); } }
private IFeatureLayer addLayer(string path, string name, bool isForObserved, bool isWorkingLayer) { Debug.WriteLine(DateTime.Now); Debug.WriteLine("Adding Layer..., " + name); if (!System.IO.File.Exists(path)) { Debug.WriteLine(path + " doesn't exist!"); return(null); } IFeatureLayer layer = this.Layers.Add(path) as IFeatureLayer; layer.SelectionEnabled = isWorkingLayer; layer.LegendText = name; foreach (DataColumn col in layer.DataSet.DataTable.Columns) { col.ColumnName = col.ColumnName.ToLower(); } //working layer and result display if (isWorkingLayer && !isForObserved) { //add result column DataTable dt = layer.DataSet.DataTable; dt.Columns.Add(RESULT_COLUMN, typeof(double)); //create schema for result display layer.Symbology.EditorSettings.ClassificationType = ClassificationType.Quantities; layer.Symbology.EditorSettings.FieldName = RESULT_COLUMN; layer.Symbology.EditorSettings.IntervalMethod = IntervalMethod.Quantile; layer.Symbology.EditorSettings.IntervalSnapMethod = IntervalSnapMethod.SignificantFigures; layer.Symbology.EditorSettings.IntervalRoundingDigits = 3; //3 significant number layer.Symbology.EditorSettings.StartSize = 5; layer.Symbology.EditorSettings.EndSize = 25; layer.Symbology.EditorSettings.NumBreaks = 5; layer.Symbology.EditorSettings.UseSizeRange = true; //start and end color layer.Symbology.EditorSettings.StartColor = Color.Green; layer.Symbology.EditorSettings.EndColor = Color.Red; } //set normal symbol //for result display, this is just the initial symbol. The symbol would be updated based on result //after the result is retrieved. if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Polygon) //subbasin { layer.Symbolizer = new PolygonSymbolizer(System.Drawing.Color.LightGray, System.Drawing.Color.Black, 0.5); //show label for subbasin MapLabelLayer label = new MapLabelLayer(); label.Symbology.Categories[0].Expression = "[" + ID_COLUMN_NAME + "]"; layer.LabelLayer = label; layer.ShowLabels = true; } else if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Line) //reach { layer.Symbolizer = new LineSymbolizer(System.Drawing.Color.Blue, 3.0); //set selection sysmbol for reach as wider red to make it more obvious layer.SelectionSymbolizer = new LineSymbolizer(System.Drawing.Color.Red, 3.0); } else if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Point) //reservoir { //set the symbol color,shape and size layer.Symbolizer = new PointSymbolizer(Color.Green, DotSpatial.Symbology.PointShape.Hexagon, 20.0); layer.SelectionSymbolizer = new PointSymbolizer(Color.Cyan, DotSpatial.Symbology.PointShape.Hexagon, 20.0); //also set to just show reservoir //first to see if there are some reservoir there Type = R if (layer.DataSet.DataTable.Rows.Count == 0) { Layers.Remove(layer as IMapLayer); return(null); } int reservoirNum = int.Parse(layer.DataSet.DataTable.Compute("count(" + ID_COLUMN_NAME + ")", "type = 'R' or type = 'r'").ToString()); if (reservoirNum <= 0) { Layers.Remove(layer as IMapLayer); return(null); } //only show reservoir List <int> hiddenMoniterPoints = new List <int>(); for (int i = 0; i < layer.DataSet.DataTable.Rows.Count; i++) { ArcSWAT.RowItem item = new ArcSWAT.RowItem(layer.DataSet.DataTable.Rows[i]); string type = item.getColumnValue_String("type"); if (!type.Equals("R") && !type.Equals("r")) { hiddenMoniterPoints.Add(i); } } layer.RemoveFeaturesAt(hiddenMoniterPoints); } //add a column to show if the feature has observed data if (isForObserved) { //add observed column DataTable dt = layer.DataSet.DataTable; dt.Columns.Add(OBSERVED_COLUMN, typeof(int)); //create schema observed column to make feature with observed data more obvious if (layer.DataSet.FeatureType != DotSpatial.Topology.FeatureType.Polygon) { layer.Symbology.ClearCategories(); //get the observed data status ArcSWAT.SWATUnitType unitType = ArcSWAT.SWATUnitType.RCH; if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Point) { unitType = ArcSWAT.SWATUnitType.RES; } foreach (DataRow r in layer.DataSet.DataTable.Rows) { int id = getIDFromFeatureRow(r); if (_project.Observation(Interval).getObservedData(unitType, id).Count > 0) { r[OBSERVED_COLUMN] = 1; } else { r[OBSERVED_COLUMN] = 0; } } //set the category IFeatureCategory cat_observed = layer.Symbology.CreateNewCategory(Color.Blue, 3.0) as IFeatureCategory; cat_observed.FilterExpression = string.Format("[{0}]=0", OBSERVED_COLUMN.ToUpper()); IFeatureCategory cat_no_observed = layer.Symbology.CreateNewCategory(Color.Red, 3.0) as IFeatureCategory; cat_no_observed.FilterExpression = string.Format("[{0}]=1", OBSERVED_COLUMN.ToUpper()); //for reservoir, change default size and shape if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Point) { cat_observed.SelectionSymbolizer = new PointSymbolizer(Color.Cyan, DotSpatial.Symbology.PointShape.Hexagon, 20.0); cat_no_observed.SelectionSymbolizer = new PointSymbolizer(Color.Cyan, DotSpatial.Symbology.PointShape.Hexagon, 20.0); ((cat_observed.Symbolizer as PointSymbolizer).Symbols[0] as SimpleSymbol).Size = new Size2D(20.0, 20.0); ((cat_no_observed.Symbolizer as PointSymbolizer).Symbols[0] as SimpleSymbol).Size = new Size2D(20.0, 20.0); ((cat_observed.Symbolizer as PointSymbolizer).Symbols[0] as SimpleSymbol).PointShape = DotSpatial.Symbology.PointShape.Hexagon; ((cat_no_observed.Symbolizer as PointSymbolizer).Symbols[0] as SimpleSymbol).PointShape = DotSpatial.Symbology.PointShape.Hexagon; } layer.Symbology.AddCategory(cat_observed); layer.Symbology.AddCategory(cat_no_observed); layer.ApplyScheme(layer.Symbology); } } if (isWorkingLayer) { layer.SelectionEnabled = true; //for selection changed event layer.SelectionChanged += (ss, _e) => { if (onLayerSelectionChanged == null) { return; } ArcSWAT.SWATUnitType unitType = ArcSWAT.SWATUnitType.SUB; if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Point) { unitType = ArcSWAT.SWATUnitType.RES; } else if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Line) { unitType = ArcSWAT.SWATUnitType.RCH; } int id = -1; if (layer.Selection.NumRows() > 0) { IFeature fea = layer.Selection.ToFeatureList()[0]; id = getIDFromFeatureRow(fea.DataRow); } onLayerSelectionChanged(unitType, id); _id = id; }; } return(layer); }