예제 #1
0
 /// <summary>
 /// Creates a new instance of a DrawnState class for subdividing features.
 /// </summary>
 /// <param name="category">A category that the feature belongs to</param>
 /// <param name="selected">Boolean, true if the feature is currently selected</param>
 /// <param name="chunk">An integer chunk that this feature should belong to</param>
 /// <param name="visible">A boolean indicating whether this feature is visible or not</param>
 public DrawnState(IFeatureCategory category, bool selected, int chunk, bool visible)
 {
     SchemeCategory = category;
     IsSelected = selected;
     IsVisible = visible;
     Chunk = chunk;
 }
예제 #2
0
 /// <inheritdoc />
 protected override void OnDeactivate()
 {
     DeselectFeature();
     RemoveHighlightFromFeature();
     _oldCategory = null;
     base.OnDeactivate();
 }
예제 #3
0
        /// <summary>
        /// Adding a feature state sets the drawing state of the item to be
        /// </summary>
        /// <param name="item">The item to add to this category</param>
        /// <exception cref="Serialization.ReadOnlyException">Occurs if this list is set to read-only in the constructor</exception>
        public void Add(IFeature item)
        {
            if (_isReadOnly)
            {
                throw new ReadOnlyException();
            }
            IDrawnState      previousState = _filter[item];
            IFeatureCategory cat           = previousState.SchemeCategory;

            if (_useCategory)
            {
                cat = _category;
            }
            bool sel = previousState.IsSelected;

            if (_useSelection)
            {
                sel = _selected;
            }
            int chunk = previousState.Chunk;

            if (_useChunks)
            {
                chunk = _chunk;
            }
            bool vis = previousState.IsVisible;

            if (_useVisibility)
            {
                vis = _visible;
            }

            _filter[item] = new DrawnState(cat, sel, chunk, vis);
            OnChanged();
        }
예제 #4
0
 /// <summary>
 /// Creates a new instance of a DrawnState class for subdividing features.
 /// </summary>
 /// <param name="category">A category that the feature belongs to</param>
 /// <param name="selected">Boolean, true if the feature is currently selected</param>
 /// <param name="chunk">An integer chunk that this feature should belong to</param>
 /// <param name="visible">A boolean indicating whether this feature is visible or not</param>
 public DrawnState(IFeatureCategory category, bool selected, int chunk, bool visible)
 {
     _category = category;
     _isSelected = selected;
     _isVisible = visible;
     _chunk = chunk;
 }
예제 #5
0
 /// <summary>
 /// Creates a new instance of a DrawnState class for subdividing features.
 /// </summary>
 /// <param name="category">A category that the feature belongs to</param>
 /// <param name="selected">Boolean, true if the feature is currently selected</param>
 /// <param name="chunk">An integer chunk that this feature should belong to</param>
 /// <param name="visible">A boolean indicating whether this feature is visible or not</param>
 public DrawnState(IFeatureCategory category, bool selected, int chunk, bool visible)
 {
     _category   = category;
     _isSelected = selected;
     _isVisible  = visible;
     _chunk      = chunk;
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DrawnState"/> class for subdividing features.
 /// </summary>
 /// <param name="category">A category that the feature belongs to.</param>
 /// <param name="selected">Boolean, true if the feature is currently selected.</param>
 /// <param name="chunk">An integer chunk that this feature should belong to.</param>
 /// <param name="visible">A boolean indicating whether this feature is visible or not.</param>
 public DrawnState(IFeatureCategory category, bool selected, int chunk, bool visible)
 {
     SchemeCategory = category;
     IsSelected     = selected;
     IsVisible      = visible;
     Chunk          = chunk;
 }
예제 #7
0
        private void CreateUniqueCategories(string fieldName, IAttributeSource source, ICancelProgressHandler progressHandler)
        {
            Breaks = GetUniqueValues(fieldName, source, progressHandler);

            string fieldExpression = "[" + fieldName.ToUpper() + "]";

            ClearCategories();

            bool isStringField = CheckFieldType(fieldName, source);

            ProgressMeter pm = new ProgressMeter(progressHandler, "Building Feature Categories", Breaks.Count);

            List <double> sizeRamp  = GetSizeSet(Breaks.Count);
            List <Color>  colorRamp = GetColorSet(Breaks.Count);

            for (int colorIndex = 0; colorIndex < Breaks.Count; colorIndex++)
            {
                Break brk = Breaks[colorIndex];

                // get the color for the category
                Color            randomColor = colorRamp[colorIndex];
                double           size        = sizeRamp[colorIndex];
                IFeatureCategory cat         = CreateNewCategory(randomColor, size) as IFeatureCategory;
                if (cat != null)
                {
                    cat.LegendText = brk.Name;
                    if (isStringField)
                    {
                        cat.FilterExpression = fieldExpression + "= '" + brk.Name.Replace("'", "''") + "'";
                    }
                    else
                    {
                        cat.FilterExpression = fieldExpression + "=" + brk.Name;
                    }

                    if (cat.FilterExpression != null)
                    {
                        if (cat.FilterExpression.Contains("=[NULL]"))
                        {
                            cat.FilterExpression = cat.FilterExpression.Replace("=[NULL]", " is NULL");
                        }
                        else if (cat.FilterExpression.Contains("= '[NULL]'"))
                        {
                            cat.FilterExpression = cat.FilterExpression.Replace("= '[NULL]'", " is NULL");
                        }
                    }

                    AddCategory(cat);
                }

                colorIndex++;
                pm.CurrentValue = colorIndex;
            }

            pm.Reset();
        }
예제 #8
0
 private void Configure()
 {
     // Cache the active state of the filter.
     _selected       = _filter.Selected;
     _selectionState = _filter.Selected;
     _visible        = _filter.Visible;
     _chunk          = _filter.Chunk;
     _category       = _filter.Category;
     _useSelection   = _filter.UseSelection;
     _useChunks      = _filter.UseChunks;
     _useVisibility  = _filter.UseVisibility;
     _useCategory    = _filter.UseCategory;
 }
예제 #9
0
        private void CreateUniqueCategories(string fieldName, DataTable table)
        {
            Breaks = GetUniqueValues(fieldName, table);
            List <double> sizeRamp        = GetSizeSet(Breaks.Count);
            List <Color>  colorRamp       = GetColorSet(Breaks.Count);
            string        fieldExpression = "[" + fieldName.ToUpper() + "]";

            ClearCategories();

            bool isStringField = CheckFieldType(fieldName, table);

            int colorIndex = 0;

            foreach (Break brk in Breaks)
            {
                //get the color for the category
                Color            randomColor = colorRamp[colorIndex];
                double           size        = sizeRamp[colorIndex];
                IFeatureCategory cat         = CreateNewCategory(randomColor, size) as IFeatureCategory;

                if (cat != null)
                {
                    //cat.SelectionSymbolizer = _selectionSymbolizer.Copy();
                    cat.LegendText = brk.Name;

                    if (isStringField)
                    {
                        cat.FilterExpression = fieldExpression + "= '" + brk.Name.Replace("'", "''") + "'";
                    }
                    else
                    {
                        cat.FilterExpression = fieldExpression + "=" + brk.Name;
                    }
                    if (cat.FilterExpression != null)
                    {
                        if (cat.FilterExpression.Contains("=[NULL]"))
                        {
                            cat.FilterExpression = cat.FilterExpression.Replace("=[NULL]", " is NULL");
                        }
                        else if (cat.FilterExpression.Contains("= '[NULL]'"))
                        {
                            cat.FilterExpression = cat.FilterExpression.Replace("= '[NULL]'", " is NULL");
                        }
                    }

                    AddCategory(cat);
                }

                colorIndex++;
            }
        }
예제 #10
0
        public int IndexOf(IFeatureCategory item)
        {
            var category = item.GetInternal();

            for (int i = 0; i < _categories.Count; i++)
            {
                if (_categories.Item[i] == category)
                {
                    return(i);
                }
            }

            return(-1);
        }
예제 #11
0
        private void BuildPaths(MapArgs e, IEnumerable <IFeature> features, out Dictionary <FastDrawnState, GraphicsPath> borderPaths, bool selected)
        {
            borderPaths = new Dictionary <FastDrawnState, GraphicsPath>();

            if (selected && !DrawingFilter.DrawnStates.Any(_ => _.Value.IsSelected))
            {
                return;
            }

            Rectangle          clipRect    = ComputeClippingRectangle(e);
            Extent             drawExtents = e.PixelToProj(clipRect);
            SoutherlandHodgman shClip      = new SoutherlandHodgman(clipRect);

            var featureList = features as IList <IFeature> ?? features.ToList();

            foreach (var category in Symbology.Categories)
            {
                // Determine the subset of the specified features that are visible and match the category
                IFeatureCategory         polygonCategory = category;
                Func <IDrawnState, bool> isMember;

                if (selected)
                {
                    // get only selected features
                    isMember = state => state.SchemeCategory == polygonCategory && state.IsVisible && state.IsSelected;
                }
                else
                {
                    // get all features
                    isMember = state => state.SchemeCategory == polygonCategory && state.IsVisible;
                }

                var drawnFeatures = (from feature in featureList where isMember(DrawingFilter[feature]) select feature).ToList();

                if (drawnFeatures.Count > 0)
                {
                    GraphicsPath borderPath = new GraphicsPath();
                    foreach (IFeature f in drawnFeatures)
                    {
                        BuildPolygon(DataSet.Vertex, f.ShapeIndex, borderPath, e, drawExtents.Contains(f.Geometry.EnvelopeInternal) ? null : shClip);
                    }

                    borderPaths.Add(new FastDrawnState(selected, category), borderPath);
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Removes the specified item from the subset of this classification if that category is used.
        /// Selected -> !Selected
        /// Category[>0] -> Category[0]
        /// Category[0] -> Null
        /// Visible -> !Visible
        /// Chunk -> -1  or basically a chunk index that is never drawn.
        /// </summary>
        /// <param name="item">The item to change the drawing state of.</param>
        /// <returns>Boolean, false if the item does not match the current grouping.</returns>
        /// <exception cref="ReadOnlyException">Occurs if this list is set to read-only in the constructor.</exception>
        public bool Remove(IFeature item)
        {
            if (IsReadOnly)
            {
                throw new ReadOnlyException();
            }

            if (Contains(item) == false)
            {
                return(false);
            }

            IDrawnState      previousState = Filter[item];
            IFeatureCategory cat           = previousState.SchemeCategory;
            int  chunk = previousState.Chunk;
            bool sel   = previousState.IsSelected;
            bool vis   = previousState.IsVisible;

            if (ActiveType == FilterType.Category)
            {
                cat = Category != Filter.DefaultCategory ? Filter.DefaultCategory : null;
            }

            if (ActiveType == FilterType.Chunk)
            {
                // removing from a chunk effectively means setting to -1 so that it will not get drawn
                // until it is added to a chunk again.
                chunk = -1;
            }

            if (ActiveType == FilterType.Selection)
            {
                sel = !Selected;
            }

            if (ActiveType == FilterType.Visible)
            {
                vis = !Visible;
            }

            Filter[item] = new DrawnState(cat, sel, chunk, vis);
            _envelope    = null; //reset the envelope so it will be calculated from the selected features the next time the property is accessed
            OnChanged();
            return(true);
        }
예제 #13
0
        /// <summary>
        /// This describes how to launch the form etc.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            _context = context;

            IWindowsFormsEditorService dialogProvider = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            SQLExpressionDialog        dlgExpression  = new SQLExpressionDialog();
            string original = (string)value;

            dlgExpression.Expression = (string)value;

            // Try to find the Table
            IFeatureCategory category = context.Instance as IFeatureCategory;

            if (category != null)
            {
                IFeatureScheme scheme = category.GetParentItem() as IFeatureScheme;
                if (scheme != null)
                {
                    IFeatureLayer layer = scheme.GetParentItem() as IFeatureLayer;
                    if (layer != null)
                    {
                        dlgExpression.Table = layer.DataSet.DataTable;
                    }
                }
                else
                {
                    IFeatureLayer layer = category.GetParentItem() as IFeatureLayer;
                    if (layer != null)
                    {
                        dlgExpression.Table = layer.DataSet.DataTable;
                    }
                }
            }

            dlgExpression.ChangesApplied += DlgExpressionChangesApplied;
            var result = dialogProvider.ShowDialog(dlgExpression);

            dlgExpression.ChangesApplied -= DlgExpressionChangesApplied;
            return(result != DialogResult.OK ? original : dlgExpression.Expression);
        }
예제 #14
0
        /// <summary>
        /// Removes the specified item from the subset of this classification if that category is used.
        /// Selected -> !Selected
        /// Category[>0] -> Category[0]
        /// Category[0] -> Null
        /// Visible -> !Visible
        /// Chunk -> -1  or basically a chunk index that is never drawn.
        /// </summary>
        /// <param name="item">The item to change the drawing state of</param>
        /// <returns>Boolean, false if the item does not match the current grouping</returns>
        /// <exception cref="ReadOnlyException">Occurs if this list is set to read-only in the constructor</exception>
        public bool Remove(IFeature item)
        {
            if (_isReadOnly)
            {
                throw new ReadOnlyException();
            }
            if (Contains(item) == false)
            {
                return(false);
            }

            IDrawnState      previousState = _filter[item];
            IFeatureCategory cat           = previousState.SchemeCategory;
            int  chunk = previousState.Chunk;
            bool sel   = previousState.IsSelected;
            bool vis   = previousState.IsVisible;

            if (_activeType == FilterType.Category)
            {
                cat = _category != _filter.DefaultCategory ? _filter.DefaultCategory : null;
            }
            if (_activeType == FilterType.Chunk)
            {
                // removing from a chunk effectively means setting to -1 so that it will not get drawn
                // until it is added to a chunk again.
                chunk = -1;
            }
            if (_activeType == FilterType.Selection)
            {
                sel = !_selected;
            }
            if (_activeType == FilterType.Visible)
            {
                vis = !_visible;
            }
            _filter[item] = new DrawnState(cat, sel, chunk, vis);
            OnChanged();
            return(true);
        }
예제 #15
0
        /// <summary>
        /// Adding a feature state sets the drawing state of the item to be.
        /// </summary>
        /// <param name="item">The item to add to this category.</param>
        /// <exception cref="Serialization.ReadOnlyException">Occurs if this list is set to read-only in the constructor.</exception>
        public void Add(IFeature item)
        {
            if (IsReadOnly)
            {
                throw new ReadOnlyException();
            }

            IDrawnState      previousState = Filter[item];
            IFeatureCategory cat           = previousState.SchemeCategory;

            if (UseCategory)
            {
                cat = Category;
            }
            bool sel = previousState.IsSelected;

            if (UseSelection)
            {
                sel = Selected;
            }
            int chunk = previousState.Chunk;

            if (UseChunks)
            {
                chunk = Chunk;
            }
            bool vis = previousState.IsVisible;

            if (UseVisibility)
            {
                vis = Visible;
            }

            Filter[item] = new DrawnState(cat, sel, chunk, vis);
            _envelope    = null; //reset the envelope so it will be calculated from the selected features the next time the property is accessed
            OnChanged();
        }
예제 #16
0
        private IFeatureScheme CreateCategoryScheme(TFeatureBasedMapData mapData)
        {
            IFeatureScheme scheme = CreateScheme();

            scheme.ClearCategories();
            scheme.AddCategory(CreateDefaultCategory(mapData));

            MapTheme <TCategoryTheme> mapTheme         = mapData.Theme;
            Dictionary <string, int>  attributeMapping = GetAttributeMapping(mapData);

            if (attributeMapping.ContainsKey(mapTheme.AttributeName))
            {
                int attributeIndex = attributeMapping[mapTheme.AttributeName];

                foreach (TCategoryTheme categoryTheme in mapTheme.CategoryThemes)
                {
                    IFeatureCategory category = CreateFeatureCategory(categoryTheme);
                    category.FilterExpression = CreateFilterExpression(attributeIndex, categoryTheme.Criterion);
                    scheme.AddCategory(category);
                }
            }

            return(scheme);
        }
예제 #17
0
        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);
        }
예제 #18
0
 /// <summary>
 /// Creates a new FastDrawnState with the specified parameters
 /// </summary>
 /// <param name="sel"></param>
 /// <param name="cat"></param>
 public FastDrawnState(bool sel, IFeatureCategory cat)
 {
     Selected = sel;
     Category = cat;
     Visible = true;
 }
예제 #19
0
        /// <summary>
        /// Given a scheme, this will build the break list to match approximately.  This does not
        /// force the interval method to build a new scheme.
        /// </summary>
        public void UpdateBreaks()
        {
            if (_isRaster)
            {
                UpdateRasterBreaks();
                return;
            }

            if (_scheme == null)
            {
                return;
            }
            IFeatureCategory selectedCat = null;

            if (_selectedSlider != null)
            {
                selectedCat = _selectedSlider.Category as IFeatureCategory;
            }
            _breaks.Clear();
            Statistics stats = _scheme.Statistics;
            Rectangle  gb    = _graph.GetGraphBounds();

            _graph.ColorRanges.Clear();
            foreach (IFeatureCategory category in _scheme.GetCategories())
            {
                ColorRange cr = new ColorRange(category.GetColor(), category.Range);
                _graph.ColorRanges.Add(cr);
                BreakSlider bs = new BreakSlider(gb, _graph.Minimum, _graph.Maximum, cr);
                bs.Color       = _breakColor;
                bs.SelectColor = _selectedBreakColor;
                if (selectedCat != null && category == selectedCat)
                {
                    bs.Selected          = true;
                    _selectedSlider      = bs;
                    _graph.SelectedRange = cr;
                }
                if (category.Maximum != null)
                {
                    bs.Value = double.Parse(category.Maximum.ToString());
                }
                else
                {
                    bs.Value = stats.Maximum;
                }
                bs.Category = category;
                _breaks.Add(bs);
            }
            _breaks.Sort();
            // Moving a break generally affects both a maximum and a minimum.
            // Point to the next category to actuate that.
            for (int i = 0; i < _breaks.Count - 1; i++)
            {
                _breaks[i].NextCategory = _breaks[i + 1].Category;
                // We use the maximums to set up breaks.  Minimums should simply
                // be set to work with the maximums of the previous category.
                _breaks[i + 1].Category.Minimum = _breaks[i].Value;
            }

            if (_breaks.Count == 0)
            {
                return;
            }
            int         breakIndex = 0;
            BreakSlider nextSlider = _breaks[breakIndex];
            int         count      = 0;

            if (_graph == null || _graph.Bins == null)
            {
                return;
            }
            foreach (double value in _values)
            {
                if (value < nextSlider.Value)
                {
                    count++;
                    continue;
                }
                nextSlider.Count = count;
                while (value > nextSlider.Value)
                {
                    breakIndex++;
                    if (breakIndex >= _breaks.Count)
                    {
                        break;
                    }
                    nextSlider = _breaks[breakIndex];
                }
                count = 0;
            }
        }
예제 #20
0
 public bool Remove(IFeatureCategory item)
 {
     return(_categories.Remove(IndexOf(item)));
 }
예제 #21
0
        /// <inheritdoc />
        protected override void OnMouseDown(GeoMouseArgs e)
        {
            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
            {
                _mousePosition = e.Location;
                if (_dragging)
                {
                    if (e.Button == MouseButtons.Right)
                    {
                        _dragging = false;
                        Map.Invalidate();
                        Map.IsBusy = false;
                    }
                }
                else
                {
                    if (_selectedFeature != null)
                    {
                        Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6);

                        Envelope env = Map.PixelToProj(mouseRect).ToEnvelope();

                        if (CheckForVertexDrag(e))
                        {
                            return;
                        }

                        // No vertex selection has occured.
                        if (!_selectedFeature.Geometry.Intersects(env.ToPolygon()))
                        {
                            // We are clicking down outside of the given polygon, so clear our selected feature
                            DeselectFeature();
                            return;
                        }
                    }

                    if (_activeFeature != null)
                    {
                        // Don't start dragging a vertices right away for polygons and lines.
                        // First you select the polygon, which displays the vertices, then they can be moved.
                        if (_featureSet.FeatureType == FeatureType.Polygon)
                        {
                            _selectedFeature = _activeFeature;
                            _activeFeature   = null;
                            IPolygonCategory sc = _selectedCategory as IPolygonCategory;
                            if (sc == null)
                            {
                                _selectedCategory = new PolygonCategory(Color.FromArgb(55, 0, 255, 255), Color.Blue, 1)
                                {
                                    LegendItemVisible = false
                                };
                            }

                            _layer.SetCategory(_selectedFeature, _selectedCategory);
                        }
                        else if (_featureSet.FeatureType == FeatureType.Line)
                        {
                            _selectedFeature = _activeFeature;
                            _activeFeature   = null;
                            ILineCategory sc = _selectedCategory as ILineCategory;
                            if (sc == null)
                            {
                                _selectedCategory = new LineCategory(Color.Cyan, 1)
                                {
                                    LegendItemVisible = false
                                };
                            }
                            _layer.SetCategory(_selectedFeature, _selectedCategory);
                        }
                        else
                        {
                            _dragging  = true;
                            Map.IsBusy = true;
                            _dragCoord = _activeFeature.Geometry.Coordinates[0];
                            MapPointLayer mpl = _layer as MapPointLayer;
                            if (mpl != null)
                            {
                                mpl.SetVisible(_activeFeature, false);
                            }
                            IPointCategory sc = _selectedCategory as IPointCategory;
                            if (sc == null)
                            {
                                IPointSymbolizer ps =
                                    _layer.GetCategory(_activeFeature).Symbolizer.Copy() as IPointSymbolizer;
                                if (ps != null)
                                {
                                    ps.SetFillColor(Color.Cyan);
                                    _selectedCategory = new PointCategory(ps);
                                }
                            }
                        }
                    }
                    Map.MapFrame.Initialize();
                    Map.Invalidate();
                }
            }
            base.OnMouseDown(e);
        }
예제 #22
0
 /// <inheritdoc />
 protected override void OnDeactivate()
 {
     DeselectFeature();
     RemoveHighlightFromFeature();
     _oldCategory = null;
     base.OnDeactivate();
 }
예제 #23
0
        /// <inheritdoc />
        protected override void OnMouseDown(GeoMouseArgs e)
        {
            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
            {
                _mousePosition = e.Location;
                if (_dragging)
                {
                    if (e.Button == MouseButtons.Right)
                    {
                        _dragging = false;
                        Map.Invalidate();
                        Map.IsBusy = false;
                    }
                }
                else
                {
                    // ÆíÁýÇÒ µµÇüÀÌ ¼±ÅõǾî ÀÖÀ¸¸é, ÆíÁýÇÒ Á¤Á¡À» ¼±ÅÃÇÕ´Ï´Ù.
                    if (_selectedFeature != null)
                    {
                        // Á¤Á¡ ¼±ÅÃÀ» À§ÇÑ ¿µ¿ªÀ» ¼³Á¤ÇÕ´Ï´Ù.
                        Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6);
                        Envelope  env       = Map.PixelToProj(mouseRect).ToEnvelope();

                        // Á¤Á¡ÀÌ ¼±ÅõǾú½À´Ï´Ù.
                        if (CheckForVertexDrag(e))
                        {
                            return;
                        }

                        // Á¤Á¡ ¼±ÅÃÀÌ ¹ß»ýÇÏÁö ¾Ê¾Ò½À´Ï´Ù.
                        if (!_selectedFeature.Geometry.Intersects(env.ToPolygon()))
                        {
                            // ¼±ÅÃÀ» Ãë¼ÒÇÕ´Ï´Ù.
                            DeselectFeature();
                            return;
                        }
                    }

                    if (_activeFeature != null)
                    {
                        // ´Ù°¢Çü°ú ¼±ÀÇ Á¤Á¡À» ¹Ù·Î µå·¡±×ÇÏÁö ¸¶½Ê½Ã¿À. ¸ÕÀú Á¤Á¡À» Ç¥½ÃÇÏ´Â ´Ù°¢ÇüÀ» ¼±ÅÃÇÑ ´ÙÀ½ À̵¿ÇÒ ¼ö ÀÖ½À´Ï´Ù.
                        if (_featureSet.FeatureType == FeatureType.Polygon) // ¸é
                        {
                            _selectedFeature = _activeFeature;
                            _activeFeature   = null;
                            if (!(_selectedCategory is IPolygonCategory sc))
                            {
                                _selectedCategory = new PolygonCategory(Color.FromArgb(55, 0, 255, 255), Color.Blue, 1)
                                {
                                    LegendItemVisible = false
                                };
                            }

                            _layer.SetCategory(_selectedFeature, _selectedCategory);
                        }
                        else if (_featureSet.FeatureType == FeatureType.Line) // ¼±
                        {
                            _selectedFeature = _activeFeature;
                            _activeFeature   = null;
                            if (!(_selectedCategory is ILineCategory sc))
                            {
                                _selectedCategory = new LineCategory(Color.Cyan, 1)
                                {
                                    LegendItemVisible = false
                                };
                            }

                            _layer.SetCategory(_selectedFeature, _selectedCategory);
                        }
                        else // Á¡
                        {
                            _dragging  = true;
                            Map.IsBusy = true;
                            _dragCoord = _activeFeature.Geometry.Coordinates[0];
                            MapPointLayer mpl = _layer as MapPointLayer;
                            mpl?.SetVisible(_activeFeature, false);

                            if (!(_selectedCategory is IPointCategory sc))
                            {
                                if (_layer.GetCategory(_activeFeature).Symbolizer.Copy() is IPointSymbolizer ps)
                                {
                                    ps.SetFillColor(Color.Cyan);
                                    _selectedCategory = new PointCategory(ps);
                                }
                            }
                        }
                    }

                    Map.MapFrame.Initialize();
                    Map.Invalidate();
                }
            }

            base.OnMouseDown(e);
        }
예제 #24
0
        /// <inheritdoc />
        public void SetCategory(IFeature feature, IFeatureCategory category)
        {
            if (_editMode)
            {
                DrawingFilter.DrawnStates[feature].SchemeCategory = category;
            }
            else
            {
                int index = DataSet.Features.IndexOf(feature);
                DrawnStates[index].Category = category;
            }

            if (!_scheme.GetCategories().Contains(category))
            {
                _scheme.InsertCategory(0, category);
            }
        }
예제 #25
0
 public void Insert(int index, IFeatureCategory item)
 {
     _categories.Insert2(index, item.GetInternal());
 }
예제 #26
0
 public void Add(IFeatureCategory item)
 {
     _categories.Add2(item.GetInternal());
 }
예제 #27
0
 internal static ShapefileCategory GetInternal(this IFeatureCategory category)
 {
     return(category.InternalObject as ShapefileCategory);
 }
예제 #28
0
        /// <inheritdoc />
        protected override void OnMouseDown(GeoMouseArgs e)
        {
            _mousePosition = e.Location;
            if (_dragging)
            {
                if (e.Button == MouseButtons.Right)
                {
                    _dragging = false;
                    Map.Invalidate();
                    Map.IsBusy = false;
                }
            }
            else
            {
                if (_selectedFeature != null)
                {
                    Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6);

                    IEnvelope env = Map.PixelToProj(mouseRect).ToEnvelope();

                    if (CheckForVertexDrag(e)) { return; }

                    // No vertex selection has occured.
                    if (!_selectedFeature.Intersects(env.ToPolygon()))
                    {
                        // We are clicking down outside of the given polygon, so clear our selected feature
                        DeselectFeature();
                        return;
                    }
                }

                if (_activeFeature != null)
                {
                    // Don't start dragging a vertices right away for polygons and lines.
                    // First you select the polygon, which displays the vertices, then they can be moved.
                    if (_featureSet.FeatureType == FeatureType.Polygon)
                    {
                        _selectedFeature = _activeFeature;
                        _activeFeature = null;
                        IPolygonCategory sc = _selectedCategory as IPolygonCategory;
                        if (sc == null)
                        {
                            _selectedCategory = new PolygonCategory(Color.FromArgb(55, 0, 255, 255), Color.Blue, 1)
                                                    {
                                                        LegendItemVisible = false
                                                    };
                        }

                        _layer.SetCategory(_selectedFeature, _selectedCategory);
                    }
                    else if (_featureSet.FeatureType == FeatureType.Line)
                    {
                        _selectedFeature = _activeFeature;
                        _activeFeature = null;
                        ILineCategory sc = _selectedCategory as ILineCategory;
                        if (sc == null)
                        {
                            _selectedCategory = new LineCategory(Color.Cyan, 1) { LegendItemVisible = false };
                        }
                        _layer.SetCategory(_selectedFeature, _selectedCategory);
                    }
                    else
                    {
                        _dragging = true;
                        Map.IsBusy = true;
                        _dragCoord = _activeFeature.Coordinates[0];
                        MapPointLayer mpl = _layer as MapPointLayer;
                        if (mpl != null)
                        {
                            mpl.SetVisible(_activeFeature, false);
                        }
                        IPointCategory sc = _selectedCategory as IPointCategory;
                        if (sc == null)
                        {
                            IPointSymbolizer ps =
                                _layer.GetCategory(_activeFeature).Symbolizer.Copy() as IPointSymbolizer;
                            if (ps != null)
                            {
                                ps.SetFillColor(Color.Cyan);
                                _selectedCategory = new PointCategory(ps);
                            }
                        }
                    }
                }
                Map.MapFrame.Initialize();
                Map.Invalidate();
            }
        }
예제 #29
0
 /// <summary>
 /// Deselects the selected feature and removes the highlight from any highlighted feature.
 /// </summary>
 public void ClearSelection()
 {
     DeselectFeature();
     RemoveHighlightFromFeature();
     _oldCategory = null;
 }
예제 #30
0
        /// <summary>
        /// Before a shape is selected, moving the mouse over a shape will highlight that shape by changing
        /// its appearance.  This tests features to determine the first feature to qualify as the highlight.
        /// </summary>
        /// <param name="e">The GeoMouseArgs parameter contains information about the mouse location
        /// and geographic coordinates.</param>
        /// <returns>A value indicating whether the shape was successfully highlighted.</returns>
        private bool ShapeHighlight(GeoMouseArgs e)
        {
            if (e == null)
                throw new ArgumentNullException("e", "e is null.");

            Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6);
            Extent ext = Map.PixelToProj(mouseRect);
            IPolygon env = ext.ToEnvelope().ToPolygon();
            bool requiresInvalidate = false;
            foreach (IFeature feature in _featureSet.Features)
            {
                if (_featureSet.FeatureType == FeatureType.Point || _featureSet.FeatureType == FeatureType.MultiPoint)
                {
                    MapPointLayer mpl = _layer as MapPointLayer;
                    if (mpl != null)
                    {
                        int w = 3;
                        int h = 3;
                        PointCategory pc = mpl.GetCategory(feature) as PointCategory;
                        if (pc != null)
                        {
                            if (pc.Symbolizer.ScaleMode != ScaleMode.Geographic)
                            {
                                Size2D size = pc.Symbolizer.GetSize();
                                w = (int)size.Width;
                                h = (int)size.Height;
                            }
                        }
                        _imageRect = new Rectangle(e.Location.X - (w / 2), e.Location.Y - (h / 2), w, h);
                        if (_imageRect.Contains(Map.ProjToPixel(feature.Coordinates[0])))
                        {
                            _activeFeature = feature;
                            _oldCategory = mpl.GetCategory(feature);
                            if (_selectedCategory == null)
                            {
                                _selectedCategory = _oldCategory.Copy();
                                _selectedCategory.SetColor(Color.Red);
                                _selectedCategory.LegendItemVisible = false;
                            }
                            mpl.SetCategory(_activeFeature, _selectedCategory);
                        }
                    }
                    requiresInvalidate = true;
                }
                else
                {
                    if (feature.Intersects(env))
                    {
                        _activeFeature = feature;
                        _oldCategory = _layer.GetCategory(_activeFeature);

                        if (_featureSet.FeatureType == FeatureType.Polygon)
                        {
                            IPolygonCategory pc = _activeCategory as IPolygonCategory;
                            if (pc == null)
                            {
                                _activeCategory = new PolygonCategory(Color.FromArgb(55, 255, 0, 0), Color.Red, 1) { LegendItemVisible = false };
                            }
                        }
                        if (_featureSet.FeatureType == FeatureType.Line)
                        {
                            ILineCategory pc = _activeCategory as ILineCategory;
                            if (pc == null)
                            {
                                _activeCategory = new LineCategory(Color.Red, 3) { LegendItemVisible = false };
                            }
                        }
                        _layer.SetCategory(_activeFeature, _activeCategory);
                        requiresInvalidate = true;
                    }
                }
            }
            return requiresInvalidate;
        }
예제 #31
0
        /// <summary>
        /// Before a shape is selected, moving the mouse over a shape will highlight that shape by changing
        /// its appearance. This tests features to determine the first feature to qualify as the highlight.
        /// </summary>
        /// <param name="e">The GeoMouseArgs parameter contains information about the mouse location
        /// and geographic coordinates.</param>
        /// <returns>A value indicating whether the shape was successfully highlighted.</returns>
        private bool ShapeHighlight(GeoMouseArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e", "e is null.");
            }

            Rectangle mouseRect          = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6);
            Extent    ext                = Map.PixelToProj(mouseRect);
            IPolygon  env                = ext.ToEnvelope().ToPolygon();
            bool      requiresInvalidate = false;

            foreach (IFeature feature in _featureSet.Features)
            {
                if (_featureSet.FeatureType == FeatureType.Point || _featureSet.FeatureType == FeatureType.MultiPoint)
                {
                    MapPointLayer mpl = _layer as MapPointLayer;
                    if (mpl != null)
                    {
                        int           w  = 3;
                        int           h  = 3;
                        PointCategory pc = mpl.GetCategory(feature) as PointCategory;
                        if (pc != null)
                        {
                            if (pc.Symbolizer.ScaleMode != ScaleMode.Geographic)
                            {
                                Size2D size = pc.Symbolizer.GetSize();
                                w = (int)size.Width;
                                h = (int)size.Height;
                            }
                        }
                        _imageRect = new Rectangle(e.Location.X - (w / 2), e.Location.Y - (h / 2), w, h);
                        if (_imageRect.Contains(Map.ProjToPixel(feature.Geometry.Coordinates[0])))
                        {
                            _activeFeature = feature;
                            _oldCategory   = mpl.GetCategory(feature);
                            if (_selectedCategory == null)
                            {
                                _selectedCategory = _oldCategory.Copy();
                                _selectedCategory.SetColor(Color.Red);
                                _selectedCategory.LegendItemVisible = false;
                            }
                            mpl.SetCategory(_activeFeature, _selectedCategory);
                        }
                    }
                    requiresInvalidate = true;
                }
                else
                {
                    if (feature.Geometry.Intersects(env))
                    {
                        _activeFeature = feature;
                        _oldCategory   = _layer.GetCategory(_activeFeature);

                        if (_featureSet.FeatureType == FeatureType.Polygon)
                        {
                            IPolygonCategory pc = _activeCategory as IPolygonCategory;
                            if (pc == null)
                            {
                                _activeCategory = new PolygonCategory(Color.FromArgb(55, 255, 0, 0), Color.Red, 1)
                                {
                                    LegendItemVisible = false
                                };
                            }
                        }
                        if (_featureSet.FeatureType == FeatureType.Line)
                        {
                            ILineCategory pc = _activeCategory as ILineCategory;
                            if (pc == null)
                            {
                                _activeCategory = new LineCategory(Color.Red, 3)
                                {
                                    LegendItemVisible = false
                                };
                            }
                        }
                        _layer.SetCategory(_activeFeature, _activeCategory);
                        requiresInvalidate = true;
                    }
                }
            }
            return(requiresInvalidate);
        }
예제 #32
0
 public bool Contains(IFeatureCategory item)
 {
     return(IndexOf(item) != -1);
 }
예제 #33
0
        /// <summary>
        /// This calculates the extent for the category and caches it in the extents collection
        /// </summary>
        /// <param name="category">
        /// </param>
        protected virtual Extent CalculateCategoryExtent(IFeatureCategory category)
        {
            Extent ext = new Extent(new[] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue });
            if (_editMode)
            {
                IDictionary<IFeature, IDrawnState> features = _drawingFilter.DrawnStates;

                foreach (IFeature f in DataSet.Features)
                {
                    if (category == features[f].SchemeCategory)
                    {
                        ext.ExpandToInclude(new Extent(f.Envelope));
                    }
                }

                if (_categoryExtents.Keys.Contains(category))
                {
                    _categoryExtents[category] = ext.Copy();
                }
                else
                {
                    _categoryExtents.Add(category, ext.Copy());
                }
            }
            else
            {
                FastDrawnState[] states = DrawnStates;
                List<ShapeRange> ranges = DataSet.ShapeIndices;
                for (int shp = 0; shp < DrawnStates.Length; shp++)
                {
                    if (states[shp].Category != null)
                    {
                        if (!_categoryExtents.ContainsKey(states[shp].Category))
                        {
                            _categoryExtents.Add(states[shp].Category, ranges[shp].Extent.Copy());
                        }
                        else
                        {
                            _categoryExtents[states[shp].Category].ExpandToInclude(ranges[shp].Extent);
                        }
                    }
                }
            }

            return ext;
        }
예제 #34
0
 /// <summary>
 /// Creates a new FastDrawnState with the specified parameters
 /// </summary>
 /// <param name="sel"></param>
 /// <param name="cat"></param>
 public FastDrawnState(bool sel, IFeatureCategory cat)
 {
     Selected = sel;
     Category = cat;
     Visible  = true;
 }
예제 #35
0
 private void Configure()
 {
     // Cache the active state of the filter.
     _selected = _filter.Selected;
     _selectionState = _filter.Selected;
     _visible = _filter.Visible;
     _chunk = _filter.Chunk;
     _category = _filter.Category;
     _useSelection = _filter.UseSelection;
     _useChunks = _filter.UseChunks;
     _useVisibility = _filter.UseVisibility;
     _useCategory = _filter.UseCategory;
 }
 protected override void OnDeactivate()
 {
     UnSelectFeature();
     UnHighlightFeature();
     _oldCategory = null;
     base.OnDeactivate();
 }