private void SimplifyAllFeatures() { UpdatingTaskProgressEventArgs args = null; var features = GetFeaturesFromTempFile().ToArray(); int index = 1; int count = features.Count(); SimplificationType simType = SimplificationType.DouglasPeucker; if (preserveTopology) { simType = SimplificationType.TopologyPreserving; } Collection <Feature> simplifiedFeatures = new Collection <Feature>(); foreach (Feature feature in features) { try { var shape = feature.GetShape(); var areaShape = shape as AreaBaseShape; var lineShape = shape as LineBaseShape; BaseShape simplifiedShape = null; if (areaShape != null) { if (selectedDistanceUnit == "Decimal Degrees") { simplifiedShape = areaShape.Simplify(simplificationTolerance, simType); } else { simplifiedShape = areaShape.Simplify(mapUnit, simplificationTolerance, (DistanceUnit)converter.ConvertBack(selectedDistanceUnit, null, null, null), simType); } } else if (lineShape != null) { if (selectedDistanceUnit == "Decimal Degrees") { simplifiedShape = lineShape.Simplify(simplificationTolerance, simType); } else { simplifiedShape = lineShape.Simplify(mapUnit, simplificationTolerance, (DistanceUnit)converter.ConvertBack(selectedDistanceUnit, null, null, null), simType); } } if (simplifiedShape != null) { Feature newFeature = new Feature(simplifiedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues); newFeature.Tag = feature.Tag; simplifiedFeatures.Add(newFeature); } } catch (Exception ex) { args = new UpdatingTaskProgressEventArgs(TaskState.Error); args.Message = feature.Id; args.Error = new ExceptionInfo(ex.Message, ex.StackTrace, ex.Source); GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); OnUpdatingProgress(args); continue; } var progressPercentage = index * 100 / count; args = new UpdatingTaskProgressEventArgs(TaskState.Updating, progressPercentage); args.Current = index; args.UpperBound = count; OnUpdatingProgress(args); isCanceled = args.TaskState == TaskState.Canceled; if (isCanceled) { break; } index++; } if (!isCanceled) { args = new UpdatingTaskProgressEventArgs(TaskState.Updating); args.Message = "Creating File"; OnUpdatingProgress(args); FileExportInfo info = new FileExportInfo(simplifiedFeatures, GetColumns(), outputPathFileName, displayProjectionParameters); Export(info); } //args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Completed); //args.Message = "Finished"; //OnUpdatingProgress(args); }
protected override void RunCore(Dictionary <string, string> parameters) { bool allParametersValid = ParseParameters(parameters); if (allParametersValid) { UpdatingProgressLongRunningTaskPluginEventArgs args = null; var features = GetFeaturesFromTempFile().ToArray(); int index = 1; int count = features.Count(); SimplificationType simType = SimplificationType.DouglasPeucker; if (preserveTopology) { simType = SimplificationType.TopologyPreserving; } Collection <Feature> simplifiedFeatures = new Collection <Feature>(); foreach (Feature feature in features) { try { var shape = feature.GetShape(); var areaShape = shape as AreaBaseShape; var lineShape = shape as LineBaseShape; BaseShape simplifiedShape = null; if (areaShape != null) { if (selectedDistanceUnit == "Decimal Degrees") { simplifiedShape = areaShape.Simplify(simplificationTolerance, simType); } else { simplifiedShape = areaShape.Simplify(mapUnit, simplificationTolerance, (DistanceUnit)converter.ConvertBack(selectedDistanceUnit, null, null, null), simType); } } else if (lineShape != null) { if (selectedDistanceUnit == "Decimal Degrees") { simplifiedShape = lineShape.Simplify(simplificationTolerance, simType); } else { simplifiedShape = lineShape.Simplify(mapUnit, simplificationTolerance, (DistanceUnit)converter.ConvertBack(selectedDistanceUnit, null, null, null), simType); } } if (simplifiedShape != null) { Feature newFeature = new Feature(simplifiedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues); newFeature.Tag = feature.Tag; simplifiedFeatures.Add(newFeature); } } catch (Exception ex) { args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Error); args.Message = feature.Id; args.ExceptionInfo = new LongRunningTaskExceptionInfo(ex.Message, ex.StackTrace); OnUpdatingProgress(args); } args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating); args.Current = index * 100 / count; OnUpdatingProgress(args); index++; } args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating); args.Message = "Creating File"; OnUpdatingProgress(args); Output(simplifiedFeatures); args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating); args.Message = "Finished"; OnUpdatingProgress(args); } else { //report error and return. } }