public DataViewerViewModel(GisEditorWpfMap map, IEnumerable <FeatureLayer> availableLayers, FeatureLayer selectedLayer, bool showSelectedFeatures, bool allowEdit, IDictionary <FeatureLayer, Collection <string> > linkColumnNames) { enableColumnVirtualization = true; this.map = map; CurrentDataTable = new DataTable(); queryConditions = new Collection <QueryConditionViewModel>(); editDataChanges = new ObservableCollection <EditDataChange>(); HightLightRowColor = DataViewerHelper.GetHightlightLayerColor(); this.showSelectedFeatures = showSelectedFeatures; changedLayers = new Collection <FeatureLayer>(); AllowEdit = allowEdit; if (availableLayers != null && availableLayers.Count() > 0) { allLayerAdapters = new ObservableCollection <FeatureLayerAdapter>(); foreach (var item in availableLayers) { Collection <string> tempUriColumnNames = new Collection <string>(); if (linkColumnNames.ContainsKey(item)) { tempUriColumnNames = linkColumnNames[item]; } FeatureLayerPlugin featureLayerPlugin = GisEditor.LayerManager.GetLayerPlugins(item.GetType()).OfType <FeatureLayerPlugin>().FirstOrDefault(); if (featureLayerPlugin != null) { bool isEfficient = featureLayerPlugin.CanPageFeaturesEfficiently; if (isEfficient) { PagedFeatureLayerAdapter shapeFileFeatureLayerDataAdapter = new PagedFeatureLayerAdapter(item, tempUriColumnNames); shapeFileFeatureLayerDataAdapter.IsLinkDataSourceEnabled = !allowEdit; shapeFileFeatureLayerDataAdapter.LoadingData += new EventHandler <ProgressChangedEventArgs>(shapeFileFeatureLayerDataAdapter_LoadingData); allLayerAdapters.Add(shapeFileFeatureLayerDataAdapter); } else { FeatureLayerAdapter featureLayerAdapter = new FeatureLayerAdapter(item, tempUriColumnNames); allLayerAdapters.Add(featureLayerAdapter); } } } if (selectedLayer != null && availableLayers.Contains(selectedLayer)) { SelectedLayerAdapter = allLayerAdapters.Where(adapter => adapter.FeatureLayer == selectedLayer).FirstOrDefault(); } else if (availableLayers.Contains(map.ActiveLayer)) { SelectedLayerAdapter = allLayerAdapters.Where(adapter => adapter.FeatureLayer == map.ActiveLayer).FirstOrDefault(); } else { SelectedLayerAdapter = allLayerAdapters.FirstOrDefault(); } } }
protected virtual SimpleShapeType GetFeatureSimpleShapeTypeCore(FeatureLayer featureLayer) { SimpleShapeType result = SimpleShapeType.Unknown; FeatureLayerPlugin plugin = GetLayerPlugins(featureLayer.GetType()).OfType <FeatureLayerPlugin>().FirstOrDefault(); if (plugin != null) { result = plugin.GetFeatureSimpleShapeType(featureLayer); } return(result); }
private void ExportMenuItem_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = (MenuItem)sender; LayerListItem layerListItem = (LayerListItem)menuItem.Tag; LayerListItem tempItem = layerListItem; while (!(tempItem.ConcreteObject is FeatureLayer)) { tempItem = tempItem.Parent; } FeatureLayer selectedLayer = tempItem.ConcreteObject as FeatureLayer; if (selectedLayer != null) { selectedLayer.Open(); RectangleShape bbox = selectedLayer.GetBoundingBox(); Collection <string> filters = ((Styles.Style)layerListItem.ConcreteObject).Filters; Collection <string> returningColumnNames = ((Styles.Style)layerListItem.ConcreteObject).GetRequiredColumnNames(); returningColumnNames = GetRequiredColumnNamesForLink(returningColumnNames, selectedLayer.FeatureSource); Collection <FeatureSourceColumn> featureColumns = selectedLayer.FeatureSource.GetColumns(); IEnumerable <string> allColumns = featureColumns.Select(c => c.ColumnName); ////LINK: //Collection<Feature> allDataFeatures = selectedLayer.FeatureSource.GetFeaturesForDrawing(bbox, GisEditor.ActiveMap.Width, GisEditor.ActiveMap.Height, allColumns, filters); ////LINK: //Collection<Feature> features = selectedLayer.FeatureSource.GetFeaturesForDrawing(bbox, GisEditor.ActiveMap.Width, GisEditor.ActiveMap.Height, returningColumnNames, filters); Collection <Feature> features = selectedLayer.FeatureSource.GetFeaturesForDrawing(bbox, GisEditor.ActiveMap.Width, GisEditor.ActiveMap.Height, returningColumnNames); ////LINK: //List<string> linkSourceNameStarts = GetLinkSourceNameStarts(selectedLayer.FeatureSource.LinkSources); //if (filters != null && filters.Count() > 0 && CheckHasLinkColumns(returningColumnNames, filters, linkSourceNameStarts)) //{ // List<Feature> resultFeatureList = features.Where(f => CheckIsValidLinkFeature(f, linkSourceNameStarts)).ToList(); // features = new Collection<Feature>(resultFeatureList); //} Collection <Feature> resultFeatures = features; // new Collection<Feature>(allDataFeatures.Where(f => features.Any(t => t.Id.Equals(f.Id))).ToList()); FeatureLayerPlugin layerPlugin = (FeatureLayerPlugin)GisEditor.LayerManager.GetLayerPlugins(selectedLayer.GetType()).FirstOrDefault(); ExportToShapeFile(resultFeatures, featureColumns, layerPlugin, selectedLayer.FeatureSource.GetFirstFeaturesWellKnownType()); } }
public static MenuItem GetViewDataMenuItem(FeatureLayerPlugin featureLayerPlugin) { var command = new ObservedCommand(() => { UserControl userControl = null; if (featureLayerPlugin == null) { FeatureLayer selectedLayer = null; if (GisEditor.LayerListManager.SelectedLayerListItem != null) { selectedLayer = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as FeatureLayer; } userControl = new DataViewerUserControl(selectedLayer); } else { userControl = featureLayerPlugin.GetViewDataUI(); } ViewData(userControl); }, () => !(GisEditor.LayerListManager.SelectedLayerListItems.Count > 0)); return(GetMenuItem("View data", "/GisEditorInfrastructure;component/Images/viewdata.png", command)); }
private void ExportToShapeFile(Collection <Feature> resultFeatures, Collection <FeatureSourceColumn> columns, FeatureLayerPlugin sourceLayerPlugin, WellKnownType type) { int count = resultFeatures.Count; if (count > 0) { FeatureLayerPlugin targetLayerPlugin = (FeatureLayerPlugin)GisEditor.LayerManager.GetLayerPlugins(typeof(ShapeFileFeatureLayer)).FirstOrDefault(); FeatureLayer resultLayer = null; if (targetLayerPlugin != null) { GetLayersParameters getLayerParameters = new GetLayersParameters(); ConfigureFeatureLayerParameters parameters = targetLayerPlugin.GetCreateFeatureLayerParameters(columns); if (parameters != null && sourceLayerPlugin != null) { bool needColumns = false; Collection <string> tempColumns = new Collection <string>(); if (parameters.CustomData.ContainsKey("Columns")) { tempColumns = parameters.CustomData["Columns"] as Collection <string>; } else { needColumns = true; } var featureColumns = columns.Where(c => needColumns || tempColumns.Contains(c.ColumnName)); if (targetLayerPlugin.CanCreateFeatureLayerWithSourceColumns(sourceLayerPlugin)) { foreach (var item in featureColumns) { FeatureSourceColumn column = new FeatureSourceColumn(item.ColumnName, item.TypeName, item.MaxLength); if (column.TypeName.Equals("c", StringComparison.InvariantCultureIgnoreCase)) { column.TypeName = "Character"; } parameters.AddedColumns.Add(column); } } else { var geoColumns = sourceLayerPlugin.GetIntermediateColumns(featureColumns); foreach (var item in geoColumns) { if (item.TypeName.Equals("c", StringComparison.InvariantCultureIgnoreCase)) { item.TypeName = "Character"; } parameters.AddedColumns.Add(item); } } parameters.WellKnownType = type; //parameters.CustomData["SourceLayer"] = featureLayer; getLayerParameters.LayerUris.Add(parameters.LayerUri); foreach (var item in parameters.CustomData) { getLayerParameters.CustomData[item.Key] = item.Value; } Proj4Projection proj4 = new Proj4Projection(); proj4.InternalProjectionParametersString = parameters.Proj4ProjectionParametersString; proj4.ExternalProjectionParametersString = GisEditor.ActiveMap.DisplayProjectionParameters; proj4.SyncProjectionParametersString(); proj4.Open(); foreach (var item in resultFeatures) { Feature feature = proj4.ConvertToInternalProjection(item); parameters.AddedFeatures.Add(feature); } if (parameters.MemoColumnConvertMode == MemoColumnConvertMode.ToCharacter) { foreach (var item in parameters.AddedColumns.Where(c => c.TypeName.Equals("Memo", StringComparison.InvariantCultureIgnoreCase)).ToList()) { item.TypeName = "Character"; item.MaxLength = 254; DbfColumn tmpDbfColumn = item as DbfColumn; if (tmpDbfColumn != null) { tmpDbfColumn.ColumnType = DbfColumnType.Character; tmpDbfColumn.Length = 254; } } } resultLayer = targetLayerPlugin.CreateFeatureLayer(parameters); resultLayer.FeatureSource.Projection = proj4; resultLayer = targetLayerPlugin.GetLayers(getLayerParameters).FirstOrDefault() as FeatureLayer; } } if (resultLayer != null) { GisEditorMessageBox messageBox = new GisEditorMessageBox(MessageBoxButton.YesNo); messageBox.Owner = Application.Current.MainWindow; messageBox.WindowStartupLocation = WindowStartupLocation.CenterOwner; messageBox.Title = GisEditor.LanguageManager.GetStringResource("NavigatePluginAddToMap"); messageBox.Message = GisEditor.LanguageManager.GetStringResource("DoYouWantToAddToMap"); messageBox.ErrorMessage = string.Empty; if (messageBox.ShowDialog().Value) { GisEditor.ActiveMap.AddLayerToActiveOverlay(resultLayer); GisEditor.ActiveMap.RefreshActiveOverlay(); RefreshArgs refreshArgs = new RefreshArgs(this, "LoadToMapCore"); InvokeRefreshPlugins(GisEditor.UIManager, refreshArgs); GisEditor.ActiveMap.Refresh(); } } } else { System.Windows.Forms.MessageBox.Show("There is no features to export.", "Export"); } }