private static void UnionFeatures() { string id = GetId(); try { var resultFeature = GeoProcessHelper.UnionAreaFeatures(SharedViewModel.Instance.EditOverlay.EditShapesLayer.InternalFeatures); SetFeatrueAttribute(resultFeature); SharedViewModel.Instance.EditOverlay.EditShapesLayer.InternalFeatures.Clear(); AddGeoProcessedFeatureToOverlay(resultFeature, id.ToString()); SharedViewModel.Instance.EditOverlay.TakeSnapshot(); } catch (Exception ex) { GisEditorMessageBox box = new GisEditorMessageBox(System.Windows.MessageBoxButton.OK); box.Owner = Application.Current.MainWindow; box.WindowStartupLocation = WindowStartupLocation.CenterOwner; box.Title = "Error"; box.Message = "An error has occurred while trying to union shapes."; box.ErrorMessage = ex.ToString(); box.ShowDialog(); GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, ex); } }
public void LoadToMap(ExceptionInfo errorInfo) { GisEditorMessageBox messageBox = new GisEditorMessageBox(MessageBoxButton.YesNo); messageBox.Title = GisEditor.LanguageManager.GetStringResource("NavigatePluginAddToMap"); messageBox.Message = String.Format(CultureInfo.InvariantCulture, "{0} is completed, do you want to add to map?", description); messageBox.ErrorMessage = errorInfo.Message; messageBox.WindowStartupLocation = WindowStartupLocation.CenterOwner; messageBox.Owner = Application.Current.MainWindow; var result = messageBox.ShowDialog().Value; if (result) { LoadToMapCore(); } }
protected override Collection <Layer> GetLayersCore(GetLayersParameters getLayersParameters) { Collection <Layer> resultLayers = base.GetLayersCore(getLayersParameters); Collection <Uri> uris = getLayersParameters.LayerUris; Collection <string> invalidFileNames = new Collection <string>(); foreach (Uri uri in uris) { var fileName = uri.LocalPath; if (ValidShapeFile(fileName)) { RemoveReadonlyAttribute(fileName); try { var shapeFileFeatureLayer = new ShapeFileFeatureLayer(fileName, GeoFileReadWriteMode.Read); shapeFileFeatureLayer.Name = Path.GetFileNameWithoutExtension(fileName); shapeFileFeatureLayer.Encoding = GetEncoding(fileName); shapeFileFeatureLayer.SimplificationAreaInPixel = 4; shapeFileFeatureLayer.RequireIndex = false; shapeFileFeatureLayer.DrawingExceptionMode = DrawingExceptionMode.DrawException; resultLayers.Add(shapeFileFeatureLayer); } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); System.Windows.Forms.MessageBox.Show(GisEditor.LanguageManager.GetStringResource("FileLayerPluginUsedByAnotherProcessText"), GisEditor.LanguageManager.GetStringResource("FileLayerPluginFilebeingusedCaption")); } } else { string shxPath = Path.ChangeExtension(fileName, ".shx"); string dbfPath = Path.ChangeExtension(fileName, ".dbf"); if (!File.Exists(fileName)) { invalidFileNames.Add(fileName); } if (!File.Exists(shxPath)) { invalidFileNames.Add(shxPath); } if (!File.Exists(dbfPath)) { invalidFileNames.Add(dbfPath); } } } if (invalidFileNames.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (var item in invalidFileNames) { sb.Append(item + ", "); } GisEditorMessageBox messageBox = new GisEditorMessageBox(MessageBoxButton.OK); messageBox.Title = GisEditor.LanguageManager.GetStringResource("MissingShapefilesCaption"); messageBox.Message = GisEditor.LanguageManager.GetStringResource("SomeShapeFilesMissingMessage"); messageBox.ErrorMessage = string.Format(errorMessageFormat, sb.Remove(sb.Length - 2, 2).ToString()); messageBox.ShowDialog(); } return(resultLayers); }
private static void ExportToShapeFile(Collection <Feature> resultFeatures, Collection <FeatureSourceColumn> columns, FeatureLayerPlugin sourceLayerPlugin, WellKnownType type) { int count = resultFeatures.Count; if (count > 0) { ShapeFileFeatureLayerPlugin targetLayerPlugin = GisEditor.LayerManager.GetActiveLayerPlugins <ShapeFileFeatureLayerPlugin>().FirstOrDefault(); FeatureLayer resultLayer = null; GetLayersParameters getLayerParameters = new GetLayersParameters(); if (targetLayerPlugin != null) { 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()) { //parameters.AddedColumns.Remove(item); 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(null, "LoadToMapCore"); InvokeRefreshPlugins(GisEditor.UIManager, refreshArgs); GisEditor.ActiveMap.Refresh(); } } } else { System.Windows.Forms.MessageBox.Show("There's no features in this layer.", "Export File"); } }