private void Configure(IFeatureList features, IFeatureScheme scheme) { _featureList = features; _scheme = scheme; //features.FeatureAdded += new EventHandler<FeatureEventArgs>(features_FeatureAdded); //features.FeatureRemoved += new EventHandler<FeatureEventArgs>(features_FeatureRemoved); }
protected void ApplyScheme(IMapFeatureLayer gridLayer, string fieldName) { IFeatureScheme newScheme = gridLayer.Symbology; newScheme.EditorSettings.NumBreaks = 5; newScheme.EditorSettings.UseGradient = true; newScheme.EditorSettings.ClassificationType = ClassificationType.Quantities; newScheme.EditorSettings.FieldName = fieldName; newScheme.CreateCategories(gridLayer.DataSet.DataTable); newScheme.ResumeEvents(); gridLayer.ApplyScheme(newScheme); }
public void MessageReceived(Core.Result.Events.ResultLayerSelected theEvent) { if (theEvent.ResultSet == null) { this.resultsGroup.Layers.Remove(this.resultsLayer); this.resultsLayer = null; return; } if (this.curResultsSet != theEvent.ResultSet) { SetupResultsMapGroup(theEvent.ResultSet); } if (this.resultsLayer == null) { return; } var layers = theEvent.SelectedLayers; IFeatureScheme scheme = this.resultsLayer.Symbology.Clone() as IFeatureScheme; this.resultsLayer.Symbology.SuspendEvents(); scheme.ClearCategories(); for (int i = 0; i < layers.Count; i++) { var cat = new LineCategory(this.colorList[i % this.colorList.Count], 1); string filter = "[LayerName] = '" + layers[i] + "'"; cat.FilterExpression = filter; cat.LegendText = layers[i]; scheme.AddCategory(cat); } BeginInvoke(new MethodInvoker(delegate { this.resultsLayer.Symbology.CopyProperties(scheme); this.resultsLayer.Symbology.ResumeEvents(); })); }
/// <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); }
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); }
/// <summary> /// Creates a new instance of DrawingFilter without using any chunks. The use chunks /// value will be false, and sub-categories will not be selected based on the chunk. /// </summary> public DrawingFilter(IFeatureList features, IFeatureScheme scheme) { _useChunks = false; _chunkSize = -1; Configure(features, scheme); }
/// <summary> /// Creates a new instance of DrawingFilter, sub-dividing the features into chunks. /// regardless of selection or category, chunks simply subdivide the filter /// into chunks of equal size. /// </summary> public DrawingFilter(IFeatureList features, IFeatureScheme scheme, int chunkSize) { _useChunks = true; _chunkSize = chunkSize; Configure(features, scheme); }
/// <summary> /// This will use the filter expressions on the categories to change the categories for those members. /// This means that an item will be classified as the last filter that it qualifies for. /// </summary> /// <param name="scheme">The scheme of categories to apply to the drawing states</param> public void ApplyScheme(IFeatureScheme scheme) { _scheme = scheme; if (_isInitialized == false) { DoInitialize(); } var fc = _scheme.GetCategories().ToList(); // Short cut the rest of this (and prevent loading features) in the case where we know everything is in the default category if (fc.Count == 1 && string.IsNullOrEmpty(fc[0].FilterExpression)) { // Replace SchemeCategory in _drawnStates foreach (var drawnState in _drawnStates) { drawnState.Value.SchemeCategory = fc[0]; } return; } var tables = new List <DataTable>(); // just in case there is more than one Table somehow var allRows = new List <DataRow>(); var tempList = new List <DataTable>(); var containsFID = fc.Any(category => category.FilterExpression != null && category.FilterExpression.Contains("[FID]")); foreach (var f in _featureList) { if (f.DataRow == null) { f.ParentFeatureSet.FillAttributes(); } if (f.DataRow != null) { DataTable t = f.DataRow.Table; if (tables.Contains(t) == false) { tables.Add(t); if (containsFID && t.Columns.Contains("FID") == false) { f.ParentFeatureSet.AddFid(); tempList.Add(t); } } allRows.Add(f.DataRow); } if (_drawnStates.ContainsKey(f)) { _drawnStates[f].SchemeCategory = null; } } foreach (IFeatureCategory cat in fc) { foreach (DataTable dt in tables) { DataRow[] rows = dt.Select(cat.FilterExpression); foreach (DataRow dr in rows) { int index = allRows.IndexOf(dr); if (index != -1) { _drawnStates[_featureList[index]].SchemeCategory = cat; } } } } foreach (DataTable table in tempList) { table.Columns.Remove("FID"); } }
/// <summary> /// Sets up the Table to work with the specified layer. This should be the copy, /// and not the original. /// </summary> /// <param name="layer"></param> public void Initialize(IFeatureLayer layer) { _original = layer.Symbology; _newScheme = _original.Copy(); _source = layer.DataSet; if (!layer.DataSet.AttributesPopulated) { if (layer.DataSet.NumRows() < 100000) { _source.FillAttributes(); // for small datasets, it is better to just load and cache it. } } if (_source.AttributesPopulated) { _expressionDialog.Table = _source.DataTable; } else { _expressionDialog.AttributeSource = _source; } _schemeType = GetSchemeType(layer); if (_schemeType != SymbolizerType.Polygon) { chkUseGradients.Visible = false; angGradientAngle.Visible = false; } else { chkUseGradients.Visible = true; angGradientAngle.Visible = true; } if (_schemeType == SymbolizerType.Point) { IPointScheme ps = _newScheme as IPointScheme; if (ps != null) { IPointSymbolizer sym; if (ps.Categories.Count == 0 || ps.Categories[0].Symbolizer == null) { sym = new PointSymbolizer(); } else { sym = ps.Categories[0].Symbolizer; } _ignoreRefresh = true; featureSizeRangeControl1.SizeRange = new FeatureSizeRange(sym, _newScheme.EditorSettings.StartSize, _newScheme.EditorSettings.EndSize); featureSizeRangeControl1.Initialize(new SizeRangeEventArgs(_newScheme.EditorSettings.StartSize, _newScheme.EditorSettings.EndSize, sym, _newScheme.EditorSettings.UseSizeRange)); featureSizeRangeControl1.Scheme = ps; featureSizeRangeControl1.Visible = true; _ignoreRefresh = false; } } else if (_schemeType == SymbolizerType.Line) { ILineScheme ls = _newScheme as ILineScheme; if (ls != null) { ILineSymbolizer sym; if (ls.Categories.Count == 0 || ls.Categories[0].Symbolizer == null) { sym = new LineSymbolizer(); } else { sym = ls.Categories[0].Symbolizer; } _ignoreRefresh = true; featureSizeRangeControl1.SizeRange = new FeatureSizeRange(sym, _newScheme.EditorSettings.StartSize, _newScheme.EditorSettings.EndSize); featureSizeRangeControl1.Initialize(new SizeRangeEventArgs(_newScheme.EditorSettings.StartSize, _newScheme.EditorSettings.EndSize, sym, _newScheme.EditorSettings.UseSizeRange)); featureSizeRangeControl1.Scheme = ls; featureSizeRangeControl1.Visible = true; _ignoreRefresh = false; } } else { featureSizeRangeControl1.Visible = false; } UpdateFields(); if (_newScheme.EditorSettings.ClassificationType != ClassificationType.Quantities) return; nudCategoryCount.Enabled = true; tabScheme.Visible = true; dgvCategories.Height = 217; UpdateStatistics(false, null); }
public static IFeatureScheme OpenFeatureScheme() { IFeatureScheme featureScheme = Open <IFeatureScheme>("*.dsly|*.dsly"); return(featureScheme); }
/// <summary> /// Disposes memory objects /// </summary> /// <param name="disposeManagedResources"> /// </param> protected override void Dispose(bool disposeManagedResources) { if (disposeManagedResources) { ViewAttributes = null; LabelSetup = null; SnapShotTaken = null; SchemeApplied = null; _name = null; _scheme = null; _selection = null; _drawingFilter = null; _featureSymbolizer = null; _selectionFeatureSymbolizer = null; _categoryExtents = null; _drawnStates = null; } if (_labelLayer != null) { _labelLayer.Dispose(); } base.Dispose(disposeManagedResources); }
/// <summary> /// Occurs when setting symbology to a new scheme and allows adding event handlers /// </summary> /// <param name="scheme"> /// </param> protected virtual void OnIncludeScheme(IFeatureScheme scheme) { if (scheme == null) { return; } scheme.ItemChanged += SchemeItemChanged; scheme.SetParentItem(this); scheme.SelectFeatures += OnSelectFeatures; scheme.DeselectFeatures += OnDeselectFeatures; }
/// <summary> /// This will use the filter expressions on the categories to change the categories for those members. /// This means that an item will be classified as the last filter that it qualifies for. /// </summary> /// <param name="scheme">The scheme of categories to apply to the drawing states</param> public void ApplyScheme(IFeatureScheme scheme) { _scheme = scheme; if (_isInitialized == false) DoInitialize(); List<IFeatureCategory> fc = _scheme.GetCategories().ToList(); // Short cut the rest of this (and prevent loading features) in the case where we know everything is in the default category if (fc.Count == 1 && string.IsNullOrEmpty(fc[0].FilterExpression)) return; List<DataTable> tables = new List<DataTable>(); // just in case there is more than one Table somehow List<DataRow> allRows = new List<DataRow>(); List<DataTable> tempList = new List<DataTable>(); bool containsFID = false; IEnumerable<IFeatureCategory> categories = _scheme.GetCategories(); foreach (var category in categories) { if (category.FilterExpression != null && category.FilterExpression.Contains("[FID]")) { containsFID = true; } } foreach (IFeature f in _featureList) { if (f.DataRow == null) { f.ParentFeatureSet.FillAttributes(); } if (f.DataRow != null) { DataTable t = f.DataRow.Table; if (tables.Contains(t) == false) { tables.Add(t); if (containsFID && t.Columns.Contains("FID") == false) { f.ParentFeatureSet.AddFid(); tempList.Add(t); } } allRows.Add(f.DataRow); } if (_drawnStates.ContainsKey(f)) _drawnStates[f].SchemeCategory = null; } foreach (IFeatureCategory cat in categories) { foreach (DataTable dt in tables) { DataRow[] rows = dt.Select(cat.FilterExpression); foreach (DataRow dr in rows) { int index = allRows.IndexOf(dr); if (index != -1) { _drawnStates[_featureList[index]].SchemeCategory = cat; } } } } foreach (DataTable table in tempList) { table.Columns.Remove("FID"); } }
/// <summary> /// Occurs when setting the symbology to a new scheme and allows removing event handlers /// </summary> /// <param name="scheme"></param> protected virtual void OnExcludeScheme(IFeatureScheme scheme) { if (scheme == null) return; scheme.ItemChanged -= SchemeItemChanged; scheme.SetParentItem(null); scheme.SelectFeatures -= OnSelectFeatures; }
/// <summary> /// This will use the filter expressions on the categories to change the categories for those members. /// This means that an item will be classified as the last filter that it qualifies for. /// </summary> /// <param name="scheme">The scheme of categories to apply to the drawing states</param> public void ApplyScheme(IFeatureScheme scheme) { _scheme = scheme; if (_isInitialized == false) { DoInitialize(); } var fc = _scheme.GetCategories().ToList(); // Short cut the rest of this (and prevent loading features) in the case where we know everything is in the default category if (fc.Count == 1 && string.IsNullOrEmpty(fc[0].FilterExpression)) { // Replace SchemeCategory in _drawnStates foreach (var drawnState in DrawnStates) { drawnState.Value.SchemeCategory = fc[0]; } return; } var tables = new List <IDataTable>(); // just in case there is more than one Table somehow var allRows = new Dictionary <IDataRow, int>(); var tempList = new List <IDataTable>(); var containsFid = fc.Any(category => category.FilterExpression != null && category.FilterExpression.Contains("[FID]")); var featureIndex = 0; foreach (var f in FeatureList) { if (f.DataRow == null) { f.ParentFeatureSet.FillAttributes(); } if (f.DataRow != null) { IDataTable t = f.DataRow.Table; if (tables.Contains(t) == false) { tables.Add(t); if (containsFid && t.Columns.Contains("FID") == false) { f.ParentFeatureSet.AddFid(); tempList.Add(t); } } allRows.Add(f.DataRow, featureIndex); } if (DrawnStates.ContainsKey(f)) { DrawnStates[f].SchemeCategory = null; } featureIndex++; } foreach (IFeatureCategory cat in fc) { foreach (IDataTable dt in tables) { // CGX TRY CATCH try { IDataRow[] rows = dt.Select(cat.FilterExpression); foreach (IDataRow dr in rows) { foreach (var key in allRows.Keys) { if (key.Equals(dr)) { DrawnStates[FeatureList[allRows[key]]].SchemeCategory = cat; } } /*int index; * if (allRows.TryGetValue(dr, out index)) * { * DrawnStates[FeatureList[index]].SchemeCategory = cat; * }*/ } } catch (Exception) { } } } foreach (IDataTable table in tempList) { table.Columns.Remove("FID"); } }
public static void SaveFeatureScheme(IFeatureScheme newScheme) { Save(newScheme, "*.dsly|*.dsly"); }
/// <summary> /// This method cycles through all the Categories in the scheme and creates a new /// category. /// </summary> /// <param name="scheme"> /// The scheme to apply /// </param> protected virtual void OnApplyScheme(IFeatureScheme scheme) { // _drawingFilter.ApplyScheme(scheme); if (_editMode) { _drawingFilter.ApplyScheme(scheme); } else { List<IFeatureCategory> categories = scheme.GetCategories().ToList(); if (_drawnStatesNeeded || (_selection != null && _selection.Count > 0) || categories.Count > 1) { AssignFastDrawnStates(); } else if (categories.Count == 1) { if (categories[0].FilterExpression != null) { AssignFastDrawnStates(); } } } _categoryExtents.Clear(); OnSchemeApplied(); OnItemChanged(this); }
/// <summary> /// Applies the specified scheme to this layer, applying the filter constraints in the scheme. /// It is at this time when features are grouped as a one-time operation into their symbol /// categories, so that this doesn't have to happen independently each drawing cycle. /// </summary> /// <param name="inScheme"> /// The scheme to be applied to this layer. /// </param> public void ApplyScheme(IFeatureScheme inScheme) { OnApplyScheme(inScheme); }
protected override void Dispose(bool disposeManagedResources) { if (disposeManagedResources) { DataSet = null; Symbology = null; if (_labelLayer != null) { _labelLayer.Dispose(); _labelLayer = null; } if (_selection != null) { _selection.Changed -= SelectedFeaturesChanged; } } base.Dispose(disposeManagedResources); }