private void setLayerSchema(IFeatureLayer layer) { int selectFeaIndex = -1; for (int i = 0; i < layer.DrawnStates.Count(); i++) { if (layer.DrawnStates[i].Selected) { selectFeaIndex = i; break; } } layer.Symbology.CreateCategories(layer.DataSet.DataTable); foreach (IFeatureCategory fc in layer.Symbology.GetCategories()) { fc.ContextMenuItems.Clear(); } try { layer.ApplyScheme(layer.Symbology); //must have this to make changes work } catch { } //must after updateLayerResultColumnName to get column name correct if (selectFeaIndex > -1) { layer.Select(selectFeaIndex); } }
/// <summary> /// Handles the special case of not copying the parent during an on copy properties operation. /// </summary> /// <param name="source">The source to copy the properties from.</param> protected override void OnCopyProperties(object source) { base.OnCopyProperties(source); ILegendItem parent = GetParentItem(); IFeatureLayer p = parent as IFeatureLayer; p?.ApplyScheme(this); }
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); }